文档

支持

Tapjoy 托管货币

使用 Tapjoy Offerwall 托管货币在 Tapjoy 服务器上存储和管理用户货币余额。
阅读时间8 分钟最后更新于 2 天前

使用 Tapjoy 托管货币在 Tapjoy 服务器上存储和管理用户的虚拟货币金额。这项免费服务对所有集成 Tapjoy 发行商 SDK 的开发者均开放,确保了无需在您的应用后端存储货币。

获取货币余额

要检查用户当前的虚拟货币余额,请采用各平台对应的方法。最好是频繁调用
getCurrencyBalance
以确保余额信息准确无误。常见的余额检查时机包括以下情况:
  • ​​应用启动时
  • 应用恢复时
  • Tapjoy 视图关闭时
  • 广告位内容消失时
为了获得最佳效果,建议在广告内容结束后约 3.5 秒调用
getCurrencyBalance
。这样可以保证有足够时间处理奖励的更新。立即检查余额可能无法显示新获得的奖励。

获取货币余额

Tapjoy 致力于及时发放奖励。但是,由于可能有网络延迟,无法保证奖励立即到账。请提醒用户,完成任务的奖励可能需要一些时间才会显示。为了确保数据准确,请在固定的时间间隔和发生关键应用事件检查余额,如以下事件:
  • ​应用启动时
  • 应用恢复时
  • 关卡之间
  • 商店加载前
请参阅以下各平台对应的方法来获取货币余额:
要在 iOS 设备上获取当前的虚拟货币余额,请使用以下方法:
// This method requests the tapjoy server for current virtual currency of the user.//Get currency[Tapjoy getCurrencyBalanceWithCompletion:^(NSDictionary *parameters, NSError *error) { if (error) { //Show error message NSLog(@"getCurrencyBalance error: %@", [error localizedDescription]); } else { //Update currency value of your app NSLog(@"getCurrencyBalance returned %@: %d", parameters[@"currencyName"], [parameters[@"amount"] intValue]); }}];
completion 代码块会返回余额,其中
currencyName
表示货币名称,
amount
表示用户的总金额。如需了解实现细节,请参考 SDK 包中的示例应用程序。

检查用户是否已获得货币

当用户自上次检查余额以来获得货币时,通知用户。请参阅以下各节中每个平台的说明以完成通知设置。
为 iOS 设备添加通知观察器以检测获得的货币:
// Set the notification observer for earned-currency-notification.It's recommended that this be placed within the applicationDidBecomeActive method.[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showEarnedCurrencyAlert:) name:TJC_CURRENCY_EARNED_NOTIFICATION object:nil];// In the following method, you can set a custom message or use the default UIAlert to inform the user that they just earned some currency.- (void)showEarnedCurrencyAlert:(NSNotification*)notifyObj{ NSNumber *currencyEarned = notifyObj.object; int earnedNum = [currencyEarned intValue]; NSLog(@"Currency earned: %d", earnedNum); // Pops up a UIAlert notifying the user that they have successfully earned some currency. // This is the default alert, so you may place a custom alert here if you choose to do so. [Tapjoy showDefaultEarnedCurrencyAlert]; // This is a good place to remove this notification since it is undesirable to have a pop-up alert more than once per app run. [[NSNotificationCenter defaultCenter] removeObserver:self name:TJC_CURRENCY_EARNED_NOTIFICATION object:nil];}

花费 Tapjoy 托管货币

要花费用户的一些虚拟货币,请调用以下各节所述特定于平台的方法。
// This method call will deduct 10 virtual currencies from the user's total.[Tapjoy spendCurrency:10 completion:^(NSDictionary *parameters, NSError *error) { if (error) { NSLog(@"spendCurrency error: %@", [error localizedDescription]); } else { NSLog(@"spendCurrency returned %@: %d", parameters[@"currencyName"], [parameters[@"amount"] intValue]); }}];
您将在 completion 代码块中获知货币余额,其中的参数
currencyName
提供货币名称,
amount
提供用户的余额。

奖励 Tapjoy 托管货币

警告
要在新应用中使用此功能,请联系您的客户经理获取批准。
要向用户发放奖励的虚拟货币,请使用以下各节所述特定于平台的方法。
// This method call will award 10 virtual currencies to the user's total.[Tapjoy awardCurrency:10 completion:^(NSDictionary *parameters, NSError *error) { if (error) { NSLog(@"awardCurrency error: %@", [error localizedDescription]); } else { NSLog(@"awardCurrency returned %@: %d", parameters[@"currencyName"], [parameters[@"amount"] intValue]); }}];
您将在
completion
代码块中获知货币余额,其中的参数
currencyName
提供货币名称,
amount
提供用户的余额。

测试 Tapjoy 托管货币

要测试 Offerwall 中的任务,请向您的应用程序添加测试设备。这样可确保测试任务会出现在 Offerwall 顶部以便进行验证。

最佳实践和其他信息

  • 务必验证
    awardCurrency
    spendCurrency
    调用,仅在这些调用成功时才解锁内容。如果这些调用失败,可能会影响设备上的余额。
  • 不要仅依赖本地存储的货币值;还应使用 Tapjoy 服务器以确保数据准确。
  • 仅在扣除货币以解锁内容时才调用 spendCurrency。
  • 托管货币仅支持每个 App ID 绑定一种货币;如需多种货币,请使用自管货币。
  • Tapjoy 按设备和应用来存储货币余额,以防止不同设备间共享余额。
  • 虽然 Tapjoy 致力于快速发放奖励,但有多种因素可能导致货币奖励延迟。应在关键应用事件后定期检查余额,并提醒用户可能出现延迟。