我有一个可自动更新的订阅。当应用程序安装在新设备上时,Apple 会返回所有以前的购买收据,在这种情况下,由于它是沙盒,我每次安装时都会收到 6 张收据。然后观察者发送restoreCompleted 事务的队列。我有一种方法可以将交易发送到我的服务器以进行 Apple 验证,但由于有 6 张收据,它运行了 6 次。我真的只想处理最后发送的收据。
所以我试图计算队列中的事务,并且仅在计数达到 1 时验证收据。
这是我到目前为止所拥有的:
- (void)paymentQueue: (SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
if (myQueue == nil) {
myQueue = [SKPaymentQueue defaultQueue];
}
NSLog(@"Transactions in Array in My Store %@", [queue transactions]);
tCount =myQueue.transactions.count;
NSString *transCount = [NSString stringWithFormat:@"%d",tCount];
for (SKPaymentTransaction *transaction in transactions)
{ switch (transaction.transactionState)
{ case SKPaymentTransactionStatePurchased:
[self completeTransaction: transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction: transaction];
break;
case SKPaymentTransactionStateRestored:
if ([transCount isEqualToString:@"1"]) {
[self restoreTransaction: transaction];
}
else {
tCount--;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
});
}
default:
break;
}
}
return;
}
恢复循环,但计数不会减少。这可能是一件简单而愚蠢的事情。有人可以告诉我如何减少这个计数吗?
谢谢!