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