SDK
查看 Tapjoy 的 iOS SDK 参考,了解如何请求广告位、处理回调、显示广告内容以及集成核心 SDK 函数。
阅读时间4 分钟最后更新于 5 天前
请求广告位
首先,在文件顶部导入TJPlacement.h#import <Tapjoy/TJPlacement.h>
TJPlacement *p = [TJPlacement placementWithName:@"Main Menu" delegate:self];
[p requestContent];
预缓存内容
为了提供最佳用户体验,请在向用户显示内容之前提前请求内容。例如,如果广告位是主菜单上的按钮,您可能需要在应用程序启动时(就在 Tapjoy Connect 调用成功后)为其请求内容。如果等到最后一刻才请求内容,用户很可能需要等待内容加载并看着加载图标旋转。对于广告,这种情况会导致用户不太可能与广告互动,因此不太可能给您带来收入。TJPlacement 回调
要获取有关内容请求状态的反馈,请实现以下 TJPlacementDelegate 方法:- (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{}
显示广告位
要实际显示内容,请调用 show:[p showContentWithViewController: nil];
showContentWithViewControllershowContentWithViewControllerif (p.isContentReady) { [p showContentWithViewController: nil];} else { //handle situation where there is no content to show, or it has not yet downloaded.}
p.isContentReady重新请求内容
成功向用户显示广告位中的内容后,必须再次请求内容(例如,再次调用[p requestContent];[p showContentWithViewController: self];处理 Tapjoy 内容操作请求
某些 Tapjoy 内容类型(如奖励和内购推荐)要求代码根据该内容单元传递的参数执行操作。例如,奖励内容单元指定要奖励给用户的物品名称(字符串)和数量(整数)。实际调整用户背包以反映奖励结果的行为由应用程序处理。需调用以下 TJActionRequestDelegate 方法并从内容单元传递相应信息:- (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}
设置入口点
(可选)您可以将每个广告位的“入口点”告诉 Tapjoy。有多种预设值可供选择:TJEntryPointUnknown //Not set, but removes any value that was already setTJEntryPointOtherTJEntryPointMainMenuTJEntryPointHudTJEntryPointExitTJEntryPointFailTJEntryPointCompleteTJEntryPointInboxTJEntryPointInitialisationTJEntryPointStore
TJPlacement *placement = [TJPlacement placementWithName:@"myPlacement" delegate:nil];[placement setEntryPoint:TJEntryPointMainMenu];[placement requestContent];