本文介绍了用于iOS非消费类应用内购买的恢复按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Apple遗憾地拒绝了我的应用程序没有恢复按钮。我希望为用户提供无缝体验,但存在一些问题。
Apple have unfortunately rejected my app for not having a restore button. I wanted to have a seamless experience for the user but there are some problems.
- (void)purchaseProUpgrade
{
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
// User is prompted for iTunes username and password here (1)
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
// Then this delegate Function Will be fired
- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
if( queue.transactions.count == 0 ) {
[self setUpgradeProductId];
// User is prompted for iTunes username and password here (2)
SKPayment *payment = [SKPayment paymentWithProductIdentifier:kInAppPurchaseProUpgradeProductId];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}else {
[[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerTransactionSucceededNotification object:self userInfo:NULL];
}
}
以上是一个很好的解决方案吗?逻辑是:
Is the above a good solution? The logic would be:
- 用户按下按钮删除应用程序内购买。
- 检查是否用户已经进行了购买(用户必须输入用户名和密码)
- 如果用户已经购买,则恢复
- 如果用户有还没有购买,提示付款(用户必须再次输入密码)。
- User presses button to remove in-app purchase.
- Check if the user has already made a purchase (user has to enter username and password)
- If user has already made a purchase, restore
- If user has not already made a purchase,prompt for payment (user has to enter password again).
这种方法的问题是:
1.额外的服务器调用
2.用户必须输入两次详细信息。
The problems with this approach are:1. An additional server call2. User has to enter details twice.
有没有人真正实现了可以演示的恢复按钮?
Has anyone actually implemented a Restore button that they can demonstrate?
推荐答案
无需实现自己的逻辑
只需实现此
No need of implementing your own logicJust implement this
- (IBAction)restorePreviousTransaction:(id)sender {
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}
这将调用此方法
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
case SKPaymentTransactionStateRestored:
if ([self respondsToSelector:@selector(restoreTransaction:)]) {
[self restoreTransaction:transaction];
return;
}
这将调用这些委托方法以确保交易成功或失败
This will call these delegate methods for transaction success or failure
- (void)restoreTransaction:(SKPaymentTransaction *)transaction
-(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
这篇关于用于iOS非消费类应用内购买的恢复按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!