我正在为 iOS 实施 Auto-renewable InApp Purchase。第一个月工作正常。但我无法知道用户的订阅是否自动续订意味着当前 InApp 购买的状态是什么。
在 StackOverflow 上研究了这么多答案后,我明白我必须提供恢复按钮来恢复事务。我也实施了它,它提供了我迄今为止的所有交易。所以,我无法获得我的最后一笔交易。因此,请帮助了解上次自动更新交易的状态,以便我能够更新服务器上的状态。
以下是我用来恢复交易的代码:
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue]restoreCompletedTransactions];
并按如下方式实施其代表:
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
NSLog(@"%@",queue );
NSLog(@"Restored Transactions are once again in Queue for purchasing %@",[queue transactions]);
NSMutableArray *purchasedItemIDs = [[NSMutableArray alloc] init];
NSLog(@"received restored transactions: %zd", queue.transactions.count);
for (SKPaymentTransaction *transaction in queue.transactions)
{
NSString *productID = transaction.payment.productIdentifier;
[purchasedItemIDs addObject:productID];
NSLog (@"product id is %@" , productID.description);
NSLog (@"observationInfo is %@" , transaction.payment.productIdentifier.observationInfo);
// here put an if/then statement to write files based on previously purchased items
// example if ([productID isEqualToString: @"youruniqueproductidentifier]){write files} else { nslog sorry}
}
}
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
{
NSLog(@"Restore Error... %@",error.description);
}