应用内购买 - 存储/获取用户购买历史 |IOS [英] In app purchase - Storing/fetching user purchase history | iOS

查看:40
本文介绍了应用内购买 - 存储/获取用户购买历史 |IOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,允许用户使用应用内购买购买新的关卡/功能.据我所知,根据我的研究,我可以通过传递一组 ProductId 使用 SKProductsRequest 从 iTunesConnect 获取应用内购买产品.然后我必须检查用户是否已经购买了任何产品并相应地处理 UI.我将购买的产品 ID 存储在 NSUderDefaults 中,并根据退回的产品进行检查.对这个过程不太确定,因为用户可能计划在某个阶段删除并重新安装应用程序,我们将丢失 NSUserDefaults,从而丢失用户的购买历史记录.

I am developing an application which will allow user to purchase new levels/functionalities using In App Purchase. As far as I know based on my research that I can fetch the In App Purchase products from iTunesConnect using SKProductsRequest by passing a set of ProductIds. And then I have to check whether the user have already purchased any of the products and handle the UI accordingly. I am storing the purchased product Id in NSUderDefaults and the checking them against the returned products. Am not so sure about this procedure because user might plan to delete and reinstall the app at some stage and we'll lose NSUserDefaults and thus user's purchase history.

有什么办法可以从苹果服务器获取用户信息?或者我是否必须保留用户的购买记录.

Is there any way we can fetch user's information from apple server? Or do I have to keep a record of user's purchases on my end.

提前致谢

附言我遵循了本教程

推荐答案

您可以像这样获取包含用户已经购买的所有产品 ID 的数组 .. 即使用户卸载/重新安装您的应用程序

You can get an array contain all product id's that user already buy it like this .. even if the user uninstall/reinstall your app

- (void) checkPurchasedItems
{
   [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}//You Call This Function

//Then this delegate Function Will be fired
- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
  purchasedItemIDs = [[NSMutableArray alloc] init];

  NSLog(@"received restored transactions: %i", queue.transactions.count);
  for (SKPaymentTransaction *transaction in queue.transactions)
  {
      NSString *productID = transaction.payment.productIdentifier;
      [purchasedItemIDs addObject:productID];
  }

}

这篇关于应用内购买 - 存储/获取用户购买历史 |IOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆