且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

应用内购买 - 存储/获取用户购买历史 |IOS

更新时间:2022-12-31 10:10:25

您可以像这样获取包含用户已经购买的所有产品 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];
  }

}