SDK

1. Requesting a Placement

First, import TJPlacement.h at the top of the file.

Objective-C
Swift
#import <Tapjoy/TJPlacement.h>

Then create an instance of the TJPlacement class and initialize it with your placement name. Be sure the placement name string in your code matches the placement name in the dashboard exactly. You can also implement a delegate to receive callbacks (explained below).

Objective-C
Swift
TJPlacement *p = [TJPlacement placementWithName:@"Main Menu" delegate:self];

Finally, request the content.

Objective-C
Swift
[p requestContent];

NB: Before you request content please ensure that the Tapjoy connect call has succeeded. Do not make a request before you have observed the TJC_CONNECT_SUCCESS notification.

2. Pre-caching the content

For the best user experience, you should 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.

3. TJPlacement Callbacks

To get feedback on the status of the content request, implement the following TJPlacementDelegate methods:

Objective-C
Swift
- (void)requestDidSucceed:(TJPlacement*)placement{}  // Called when the content request returns from Tapjoy's 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{}

4. Displaying a Placement

To actually display content, call show:

Objective-C
Swift
[p showContentWithViewController: nil];

NB: If you pass ‘nil’ to showContentWithViewController the Tapjoy SDK will create it’s own view controller to handle display of the ad. In most cases this is the safest option. If you have a complex view hierarchy and for some reason want to mange the display yourself you can optionally pass a view controller of your own to showContentWithViewController. It is vitally important that the ViewController passed to this method be the top-most view and that it be unobstructed by other views, and that other views are not placed on top of this view until after the Tapjoy content has been dismissed.

You should check to make sure that content is ready before calling show:

Objective-C
Swift
if (p.isContentReady) {
   [p showContentWithViewController: nil];
}
else {
  //handle situation where there is no content to show, or it has not yet downloaded.
}    

NB: you should mute your app’s audio before showing content from a placement that might include video, otherwise the audio for the video and your app’s audio might conflict.

Often, it is a good idea to wait until the contentIsReady delegate fires before showing content to the user. This way, you can be sure that the content is actually on the device, and can be shown to the user without delay. Another equivalent way is to check to see if p.isContentReady is true, as in the example above.

5. Re-requesting the content

Once you successfully display content from a placement to a user, you must request content again (i.e. call [p requestContent]; again) to "reload" the placement with another content unit. You cannot simply call [p showContentWithViewController: self]; again. If you try to show content before requesting content, the show content will fail.

6. 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:

Objective-C
Swift
- (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 
}    

=======

7. 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:

Objective-C
Swift
TJEntryPointUnknown //Not set, but removes any value that was already set
TJEntryPointOther
TJEntryPointMainMenu
TJEntryPointHud
TJEntryPointExit
TJEntryPointFail
TJEntryPointComplete
TJEntryPointInbox 
TJEntryPointInitialisation
TJEntryPointStore 

You should set the entry point after creating your placement object, but before requesting content:

Objective-C
Swift
TJPlacement *placement = [TJPlacement placementWithName:@"myPlacement" delegate:nil];
[placement setEntryPoint:TJEntryPointMainMenu];
[placement requestContent];