开发者

Handling pending In App Purchase transactions on next launch

How to call

[[SKPaymentQueue defaultQueue] finishTransaction:transaction]; 

if before receiving the updated transaction response of

SKPaymentTransactionStatePurchased

and after actually debiting the money to a user's itunes account, the app gets killed due 开发者_运维百科to an incoming call or something.

Not doing so would not let you unlock the functionality on relaunch and trying re-purchase will give this error "You've already purchased this but it hasn't been downloaded" because you didn't finish the transaction and failed to unlock the functionality because the app got killed. But at this point the money was debited from the user's itunes account. It all happened after actual debit of money and before you receiving the response SKPaymentTransactionStatePurchased. In between the app got killed. Now what is one supposed to do under such circumstances?


The transaction queue remains active until you finish it —even if the app is killed—, just make sure you keep observing the queue on the next launch.

Note that even if multiple transactions were queued, you can distinguish them in because paymentQueue:updatedTransactions: gives you an array with each transaction and you can query their state individually. Example:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
  for (SKPaymentTransaction *transaction in transactions)
  {
    switch (transaction.transactionState)
    {
        case SKPaymentTransactionStatePurchasing:
            // Purchasing... waiting...
            break;

        case SKPaymentTransactionStatePurchased:
            // Complete transaction here
            break;

        case SKPaymentTransactionStateFailed:
            // Handle failure and finish transaction here
            break;

        case SKPaymentTransactionStateRestored:
            // Restore transaction
            break;
    }
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜