你猜对了!您唯一需要调用的是:
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
这将恢复用户已完成的所有事务。对于每笔交易,SKPaymentTransactionObserver
都会调用此方法(每次用户购买时也会调用相同的方法):
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
break;
default:
break;
}
}
}
使用 transactionState,如果需要,您可以区分交易是原始购买 ( SKPaymentTransactionStatePurchased
) 还是恢复 ( SKPaymentTransactionStateRestored
)。
如果您需要知道恢复何时完成,您可以使用:
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
NSLog(@"%d items restored", queue.transactions.count);
}