Restoring purchases in iOS

爱⌒轻易说出口 提交于 2019-12-08 07:51:29

问题


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:


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);


来源:https://stackoverflow.com/questions/14974833/restoring-purchases-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!