文档

支持

SDK

查看 Tapjoy 的 iOS SDK 参考,了解如何请求广告位、处理回调、显示广告内容以及集成核心 SDK 函数。
阅读时间4 分钟最后更新于 5 天前

请求广告位

首先,在文件顶部导入
TJPlacement.h
#import <Tapjoy/TJPlacement.h>
然后,创建 TJPlacement 类的一个实例,并使用广告位名称对其进行初始化。确保代码中的广告位名称字符串与后台中的广告位名称完全匹配。还可以实现委托来接收回调(下文对此进行了说明)。
TJPlacement *p = [TJPlacement placementWithName:@"Main Menu" delegate:self];
最后,请求内容。
[p requestContent];
在请求内容之前,请确保 Tapjoy connect 调用已成功。观察到 TJC_CONNECT_SUCCESS 通知之前,请勿发起请求。

预缓存内容

为了提供最佳用户体验,请在向用户显示内容之前提前请求内容。例如,如果广告位是主菜单上的按钮,您可能需要在应用程序启动时(就在 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];
如果向
showContentWithViewController
传递“nil”,Offerwall SDK 将创建自己的视图控制器 (view controller) 来处理广告的显示。在大多数情况下,这是最安全的选项。如果您的视图层级结构很复杂,并且出于某种原因希望自己管理广告显示,则可以选择将您自己的视图控制器传递给
showContentWithViewController
。必须确保传递给此方法的 ViewController 是最顶层的视图,此视图未被其他视图遮挡,并且在 Tapjoy 内容被移除之前,其他视图没有置于此视图之上。
在调用 show 之前,请进行检查以确保内容已准备就绪:
if (p.isContentReady) { [p showContentWithViewController: nil];} else { //handle situation where there is no content to show, or it has not yet downloaded.}
最好是在显示可能包含视频的广告位的内容之前先将应用的音频静音,否则视频的音频与应用的音频可能会发生冲突。 通常,最好等到 contentIsReady 委托触发之后再向用户显示内容。这样就可以确保内容已实际位于设备上,并可立即向用户显示而不会有延迟。另一种等效方法是检查
p.isContentReady
是否为 true,如以上示例中所示。

重新请求内容

成功向用户显示广告位中的内容后,必须再次请求内容(例如,再次调用
[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];