在我的应用程序中,我正在尝试实施“恢复购买”按钮,但我无法弄清楚如何获取订阅的最新购买收据。我只有一个SKProduct,一个可自动更新的订阅。
我只需要获取最新收据并将其发送到服务器进行验证。
我试过这个:
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
for (SKPaymentTransaction *transaction in queue.transactions) {
if (transaction.transactionState == SKPaymentTransactionStatePurchasing) {
NSLog(@"Purchasing");
}
if (transaction.transactionState == SKPaymentTransactionStatePurchased) {
NSLog(@"Purchasing");
}
if (transaction.transactionState == SKPaymentTransactionStateRestored) {
NSLog(@"Restored");
}
if (transaction.transactionState == SKPaymentTransactionStateFailed) {
NSLog(@"Failed");
}
}
}
但我得到了这个:
2013-10-04 12:21:48.994 App[5289:60b] Purchasing
2013-10-04 12:21:48.995 App[5289:60b] Purchasing
2013-10-04 12:21:48.996 App[5289:60b] Purchasing
2013-10-04 12:21:48.996 App[5289:60b] Purchasing
2013-10-04 12:21:48.997 App[5289:60b] Purchasing
2013-10-04 12:21:48.998 App[5289:60b] Purchasing
2013-10-04 12:21:48.999 App[5289:60b] Purchasing
2013-10-04 12:21:48.999 App[5289:60b] Purchasing
2013-10-04 12:21:49.000 App[5289:60b] Purchasing
2013-10-04 12:21:49.000 App[5289:60b] Restored
2013-10-04 12:21:49.001 App[5289:60b] Restored
2013-10-04 12:21:49.001 App[5289:60b] Restored
我只需要最新的收据。我怎么能得到它? 问题是由于某种原因用户购买了订阅,但无法在我的服务器上验证。为什么失败 - 我不知道。
答案 0 :(得分:0)
您可以通过以下方式获取收据:
// Load the receipt from the app bundle.
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
if (!receipt) {
/* No local receipt -- handle the error. */
}
/* ... Send the receipt data to your server ... */
这就是我所需要的。很抱歉延迟回答Nikolay Dyankov :) 有关更多详细信息,请检查here。
最好。