簡體   English   中英

用戶取消IAP iOS SDK時如何更新UI

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

我已經在ios SDK中成功實現了IAP

但是問題是當用戶單擊“還原購買”按鈕時,我通過以下代碼啟動還原:

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

而且我還編寫了以下代碼來處理和啟動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;
    }
}
 }

當我選擇還原時,會出現一個對話框,要求輸入密碼。 當我取消它時,進度hud不會隱藏。

我怎樣才能做到這一點。 用戶在過程之間取消購買時如何更新UI。

這是圖片。 在此處輸入圖片說明

當我使用委托方法時立即編輯

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

}

當它要求輸入密碼時, SVProgressHUD隱藏。 無論我按“取消”還是“確定”。 如何處理。

以及當用戶輸入正確的密碼時如何更新UI並繼續購買。

您的代表應實現此方法:

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

在這種情況下的錯誤將指示取消操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM