用户取消IAP ios sdk

时间:2015-07-23 13:44:14

标签: ios objective-c iphone xcode6 in-app-purchase

我已在IAP sdk中成功实施了ios

但问题是,当用户点击“恢复购买”按钮时,我会通过以下代码启动恢复:

 [[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。

这是图像。 enter image description here

编辑现在当我使用委托方法

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

}

当它要求输入密码时,SVProgressHUD会隐藏。不管我按取消还是OK。怎么处理这个。

如何更新UI并在用户输入正确的密码时继续购买。

1 个答案:

答案 0 :(得分:1)

您的代理人应该实施此方法:

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

这种情况下的错误将表示取消操作。