Tapjoy 托管货币
使用 Tapjoy Offerwall 托管货币在 Tapjoy 服务器上存储和管理用户货币余额。
阅读时间10 分钟最后更新于 4 天前
Tapjoy 托管货币支持在 Tapjoy 的服务器上存储用户的货币金额。这是 Tapjoy 为所有集成了 Tapjoy 发行商 SDK 的开发者提供的免费服务。通过使用此服务,免除了您为应用程序存储用户货币数据所需的常规后端工作。集成过程相对简单,下面将详细介绍集成说明。
获取货币余额
要获取用户的当前虚拟货币,请调用以下方法: 虚拟货币最佳实践: 建议尽可能频繁调用 getCurrencyBalance,以便用户的余额始终是最新数据。检查用户余额的常见时机包括:应用启动时、应用恢复运行时、Tapjoy 视图关闭时以及广告位内容消失时。通常,在广告内容消失后 3.5 秒调用 getCurrencyBalance(或任何平台上的等效方法)尤其有用。这样就能确保在您检查货币余额时,奖励已经在我们的系统中到账。如果在内容展示完成后立即调用 getCurrencyBalance,奖励可能在余额查询前尚未及时计入用户余额。如上所述,在 completion 代码块中会告知货币余额,其中的参数// 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]); }}];
currencyName检查用户是否已获得货币
为了告知用户自上次应用查询用户货币余额以来的虚拟货币收入,请设置一个通知观察器:
// 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 托管货币
要花费用户的一些虚拟货币,请调用以下方法:如上所述,在 completion 代码块中会告知货币余额,其中的参数// 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]); }}];
currencyNameamount奖励 Tapjoy 托管货币
要奖励用户一定数量的虚拟货币,请调用以下方法:
如上所述,在 completion 代码块中会告知货币余额,其中的参数// 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]); }}];
currencyNameamount测试托管货币
如果要查看 Offerwall 中的测试任务,您可以向应用程序添加测试设备。这样,测试任务将显示在 Offerwall 的顶部,因此可以轻松测试货币。 还有一个工具可用于验证 Tapjoy 托管货币实现是否正常工作,这就是 Tapjoy 后台上的“Get User Balance(获取用户余额)”工具:
getCurrencyBalance最佳实践
- 部分发行商仅在客户端通知中实现了托管货币,并将货币值存储在本地。强烈建议不要仅依赖本地存储的货币值。如果您因此遇到问题,我们将无法提供支持。如果这会对您造成困扰,您可能需要考虑使用自管货币。
- 仅当需要扣除货币来解锁物品或内容时,才应调用 。
spendCurrency - 托管货币仅支持每个 App ID 绑定一种货币。如果您有多种货币,则需采用自管货币。
- 货币余额按每个设备、每个应用分别进行存储,因此无法在设备之间共享余额。