SDK
Explore Tapjoy’s iOS SDK reference to learn how to request placements, handle callbacks, display ad content, and integrate core SDK functions.
読み終わるまでの所要時間 4 分最終更新 3日前
Requesting a Placement
First, importTJPlacement.h
#import <Tapjoy/TJPlacement.h>
TJPlacement *p = [TJPlacement placementWithName:@"Main Menu" delegate:self];
[p requestContent];
Pre-caching the content
For the best user experience, request content in advance of when the user might be shown that content. For example, if the placement is a button on your main menu, you might want to request content for it when your application starts, just after the Tapjoy Connect call succeeds. If you wait until the last moment to request content, it is likely the user will have to wait for the content to load, and watch a loading spinner. For ads, this makes the user less likely to interact with the ad, and therefore less likely to make money for you.TJPlacement Callbacks
To get feedback on the status of the content request, implement the following TJPlacementDelegate methods:- (void)requestDidSucceed:(TJPlacement*)placement{} // Called when the content request returns from the Offerwall servers. Does not necessarily mean that content is available. - (void)requestDidFail:(TJPlacement*)placement error:(NSError*)error{} - (void)contentIsReady:(TJPlacement*)placement{} //This is called when the content is actually available to display. - (void)contentDidAppear:(TJPlacement*)placement{} - (void)contentDidDisappear:(TJPlacement*)placement{}
Displaying a Placement
To actually display content, call show:[p showContentWithViewController: nil];
showContentWithViewController
showContentWithViewController
if (p.isContentReady) { [p showContentWithViewController: nil]; } else { //handle situation where there is no content to show, or it has not yet downloaded. }
p.isContentReady
Re-requesting the content
When you successfully display content from a placement to a user, you must request content again (for example, call[p requestContent];
[p showContentWithViewController: self];
Handling Tapjoy Content Action Requests
Some Tapjoy content types, like Reward and IAP Promotion, require your code to take action based on parameters passed by that content unit. For example, the Reward content unit specifies an item name (a string) and a quantity (an integer) to be given to the user. It is up to the application to actually adjust the user’s inventory to reflect the reward. The following TJActionRequestDelegate methods are called and passed the appropriate information from the content unit:- (void)placement:(TJPlacement*)placement didRequestPurchase:(TJActionRequest*)request productId:(NSString*)productId { //called when user clicks the product link in IAP promotion content //implement code here to trigger IAP purchase flow for item here } - (void)placement:(TJPlacement*)placement didRequestReward:(TJActionRequest*)request itemId:(NSString*)itemId quantity:(int)quantity { //called when the reward content is closed by the user //implement code here to give the player copies of item }
Setting the Entry Point
You can optionally tell Tapjoy the 'entry point' of each placement. There are a variety of preset values to choose from:TJEntryPointUnknown //Not set, but removes any value that was already set TJEntryPointOther TJEntryPointMainMenu TJEntryPointHud TJEntryPointExit TJEntryPointFail TJEntryPointComplete TJEntryPointInbox TJEntryPointInitialisation TJEntryPointStore
TJPlacement *placement = [TJPlacement placementWithName:@"myPlacement" delegate:nil]; [placement setEntryPoint:TJEntryPointMainMenu]; [placement requestContent];