gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 01:49:14 25 4
gpt4 key购买 nike

我已经在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com