开发者

ios InApp purchases: When and why does SKPaymentTransactionStateRestored get sent back as status of a transaction?

开发者 https://www.devze.com 2023-04-02 01:27 出处:网络
iOS In-App purchases: When and why does SKPaymentTransactionStateRestored get sent back as status of a transaction?

iOS In-App purchases: When and why does SKPaymentTransactionStateRestored get sent back as status of a transaction?

Does it related to having a recurring subscripti开发者_如何学Con plan?


You get SKPaymentTransactionStateRestored transactions instead of SKPaymentTransactionStatePurchased transactions when you are restoring the user's purchases by sending a restoreCompletedTransactions message to the SKPaymentQueue.


General rule is to process both callbacks: for purchase and restore purchase.

- (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];

        default:
            break;
        }
    }
}

- (void) completeTransaction: (SKPaymentTransaction *)transaction
{
[self recordTransaction: transaction content:transaction.payment.productIdentifier];

[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}

- (void) restoreTransaction: (SKPaymentTransaction *)transaction
{
[self recordTransaction: transaction content:transaction.originalTransaction.payment.productIdentifier];

[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
0

精彩评论

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