简体   繁体   English

用户取消IAP iOS SDK时如何更新UI

[英]How to Update UI when user cancelled IAP ios sdk

I have successfully implemented IAP in ios sdk. 我已经在ios SDK中成功实现了IAP

But the problem is when user click on Restore purchase button I initiate the restore by this code: 但是问题是当用户单击“还原购买”按钮时,我通过以下代码启动还原:

 [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

And also I have written this code to handle and initiate the purchase : 而且我还编写了以下代码来处理和启动purchase

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
for(SKPaymentTransaction *transaction in transactions){
    switch(transaction.transactionState){

        case SKPaymentTransactionStatePurchasing: NSLog(@"Transaction state -> Purchasing");
            //called when the user is in the process of purchasing, do not add any of your own code here.
            break;

        case SKPaymentTransactionStatePurchased:
            //this is called when the user has successfully purchased the package 
              [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
             [SVProgressHUD dismiss];
            [self doRemoveAds]; //you can add your code for what you want to happen when the user buys the purchase here, for this tutorial we use removing ads


            break;
        case SKPaymentTransactionStateRestored:
             [SVProgressHUD dismiss];
            NSLog(@"Transaction state -> Restored");
            //add the same code as you did from SKPaymentTransactionStatePurchased here
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            break;
        case SKPaymentTransactionStateFailed:
             [SVProgressHUD dismiss];

            //called when the transaction does not finish
            if(transaction.error.code == SKErrorPaymentCancelled){
                [SVProgressHUD dismiss];

                NSLog(@"Transaction state -> Cancelled");
                //the user cancelled the payment ;(
            }
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            break;
    }
}
 }

When I select Restore then A dialogs come which ask for password. 当我选择还原时,会出现一个对话框,要求输入密码。 When I cancel it The progress hud doesn't hides. 当我取消它时,进度hud不会隐藏。

How can I do this. 我怎样才能做到这一点。 How to update UI when user cancel purchase in between the process. 用户在过程之间取消购买时如何更新UI。

Here is the image. 这是图片。 在此处输入图片说明

EDIT now when i use the delegate method 当我使用委托方法时立即编辑

- (void)paymentQueue:(SKPaymentQueue *)queue   restoreCompletedTransactionsFailedWithError:(NSError *)error
{
 [SVProgressHUD dismiss];

}

When It asks for password the SVProgressHUD hides. 当它要求输入密码时, SVProgressHUD隐藏。 No matter I press cancel or OK. 无论我按“取消”还是“确定”。 How to handle this. 如何处理。

And How to update the UI and continue Purchase when user enters correct password. 以及当用户输入正确的密码时如何更新UI并继续购买。

Your delegate should implement this method: 您的代表应实现此方法:

- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error

The error in this case will indicate a cancel action. 在这种情况下的错误将指示取消操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM