当我的应用程序从另一台设备登录时,我正在尝试恢复以前的购买。我使用以下代码,但问题是还原从未完成。抛出错误
忽略restoreCompletedTransactionWithApplicationUsername :,因为已经在还原事务
- (void)restoreTransaction:(SKPaymentTransaction *)transaction
{
//newly added code to restore function
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
我应该等待应用程序完成还原还是这是错误?但是什么也没发生。
答案 0 :(得分:0)
我找到了解决方案。以下是代码流。
- (void) checkPurchasedItems:(CDVInvokedUrlCommand *)command
{
self.callbackId = command.callbackId;
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
- (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];
// NSLog(@"Product id in buyproduct:%@",productID);
}
CDVPluginResult* result = [CDVPluginResult
resultWithStatus:CDVCommandStatus_OK messageAsString:@"1"];
[self.commandDelegate sendPluginResult:result
callbackId:self.callbackId];
}