ios - 用户取消 IAP ios sdk 时如何更新 UI

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

我已经在 ios sdk 中成功实现了 IAP

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

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

我还编写了这段代码来处理和启动购买:

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

EDIT 当我使用委托(delegate)方法时

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

}

当它要求输入密码时,SVProgressHUD 会隐藏。无论我按取消还是确定。如何处理这个。

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

最佳答案

您的委托(delegate)应实现此方法:

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

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

关于ios - 用户取消 IAP ios sdk 时如何更新 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31589225/

相关文章:

ios - 应用程序将数据存储在 iCloud 中有哪些不同的方式,哪些方式可以从 iCloud 管理存储中看到

objective-c - 为什么release不将指针设置为nil而是让它指向已释放的内存?

objective-c - ARC 不允许将 'int' 隐式转换为 'id _Nonnull'

iphone - Codesign 返回 xcode iphone 项目的退出代码 11 -- 找不到有关退出代码 11 的文档

iphone - 使用libxml2 sax解析器时如何从xml中获取属性的名称和值?

iOS iBeacon : How to get all of proximityUUID programmatically?

ios - 是否可以使用 iOS SDK 检测 LTE 连接?

ios - 我的删除核心对象方法有什么问题?

css - 字体系列应用于 iphone 模拟器但未应用于真正的 iphone 设备?

ios - 设置缓存时间 AFNetworking swift 2