ios 恢复已在 iPhone 上购买的应用内购买?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7761556/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:52:07  来源:igfitidea点击:

Restore already bought in-app-purchases on iPhone?

iosin-app-purchaserestore

提问by Daniel Brown

I got so far: After a reinstall, a user needs to click "buy feature", then he gets scared with the $0.99 question, then has to login and then gets told the feature is already bought and he gets it for free.

我到目前为止:重新安装后,用户需要单击“购买功能”,然后他被 0.99 美元的问题吓坏了,然后必须登录,然后被告知该功能已经购买,他可以免费获得。

I know apple is a religion and users are strong believers, but isn't there a better way? :-) What I want is to check for the feature without actually buying it. Letting the user enter his account info seems to be neccessary, maybe buy a $0.00 feature? or is there a method somewhere that does this?

我知道苹果是一种宗教,用户是坚定的信徒,但没有更好的方法吗?:-) 我想要的是在不实际购买的情况下检查该功能。让用户输入他的帐户信息似乎是必要的,也许购买 0.00 美元的功能?或者有什么方法可以做到这一点?

I'm using MKStoreKit for the whole In-App-Purchase, but any solution would be great.

我在整个应用内购买中使用 MKStoreKit,但任何解决方案都会很棒。



UPDATE

更新

thanx to darvids0n, your method solved my problem! here's some working code for others trying the same:

感谢darvids0n,你的方法解决了我的问题!这是其他人尝试相同的一些工作代码:

- (void)removePreviousPurchases { //just for sandbox testing
    [[MKStoreManager sharedManager] removeAllKeychainData];
}

- (void)restorePreviousPurchases { //needs account info to be entered
    if([SKPaymentQueue canMakePayments]) {
        [[MKStoreManager sharedManager] restorePreviousTransactionsOnComplete:^(void) {
             NSLog(@"Restored.");
             /* update views, etc. */
        }
        onError:^(NSError *error) {
            NSLog(@"Restore failed: %@", [error localizedDescription]);
            /* update views, etc. */
        }];
    }
    else
    {
        NSLog(@"Parental control enabled");
        /* show parental control warning */
    }
}

采纳答案by Daniel Brown

If the $0.99 item is non-consumable, then you should provide a "Restore Purchases" button (or similar) which calls

如果 0.99 美元的物品是非消耗品,那么您应该提供一个“恢复购买”按钮(或类似的),它会调用

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

Assuming you've added a transaction observer already, and implemented the protocolincluding a case to handle a restored transaction (with state SKPaymentTransactionStateRestored) this will work.

假设你已经添加了一个交易的观察者已经,并实施了协议,包括处理一个恢复交易(与状态的情况下SKPaymentTransactionStateRestored),这将工作。

回答by manish

Add these two methods :

添加这两个方法:

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

[[SKPaymentQueue defaultQueue]restoreCompletedTransactions];