Restoring purchases in iOS

2019-05-30 08:37发布

I am working on restoring purchases, So I have few doubts

1) How to show restore button

I have shown it on top left corner, and on click of it I call this function

- (IBAction)restorePurchases:(id)sender
    {
        [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
        [[SKPaymentQueue defaultQueue]restoreCompletedTransactions];

    }

But What if the user has not purchased anyItem or what if the user has purchased an item but not deleted and reinstalled the app, Whether I still need to show the restoreButton, and if yes, on click of it what should be its behaviour.

2) Now, If I have made a purchase of an item and delete the app and reinstall the app, and click on restore button, it calls this function

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

But now, suppose I dont but anyitem and simply click restore button, it asks me for my apple Id, after entering apple Id, nothing happens, It doesnt call the above function, I want to know why this is happening.

Also, I want to display a message to user that there are no items to restore, so how can I do that.

I searched for this and their is one delegate function which will be called,if there are no transactions to retore

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{

}

What I have done is that here I have checked if there are no items to restore, I will display as no items to restore, whether I am right in this approach.

Regards Ranjit

1条回答
Fickle 薄情
2楼-- · 2019-05-30 09:12

Direct from Store Kit Header File

// Asynchronous. Will add completed transactions for the current user back to the queue to be re-completed. User will be asked to authenticate. Observers will receive 0 or more -paymentQueue:updatedTransactions:, followed by either -paymentQueueRestoreCompletedTransactionsFinished: on success or -paymentQueue:restoreCompletedTransactionsFailedWithError: on failure. In the case of partial success, some transactions may still be delivered.

- (void)restoreCompletedTransactions  __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
查看更多
登录 后发表回答