【发布时间】:2015-06-03 11:51:53
【问题描述】:
我在 App Store 中有一个应用程序,我将带来 IAPs 来解锁新版本中的功能。我已经为两种非消耗品实施了 IAP 机制,并且所有购买都运行良好。
当用户购买产品时,我设置了一个 NSUserDefault 标志,然后使用它来解锁应用程序中其他地方的功能。
这对我很有效。
我的问题是关于恢复。
我已经看到很多关于此的问题,但我不太清楚解决方案是什么。
如果用户购买 IAP,它会存储 NSUserDefault 标志。但是,如果用户使用具有相同 Apple ID 的不同设备,或者删除并重新安装应用程序,则恢复购买按钮不会检测到之前保存的 NSUserDefault(可以理解)。
- (void)restoreThePurchase
{
// Similar to the purchase
// Ask the App Store to restore rather than create a payment. We call it via the SKPaymentQueue.
// When we've sent that ot the App Store, the App Store will get back to the App Delegate and get back to the paymentQueue updated:Transactions to the restore.
[[SKPaymentQueue defaultQueue]restoreCompletedTransactions];
}
我有三个班级:
-
IAPViewController其中包含购买和恢复UIButton -
e100EntriesPurchase包含购买和恢复等 IAP 方法。 -
eUnlimitedEntriesPurchase包含无限购买以及购买和恢复的 IAP 方法。
按下恢复按钮时,我会检查设备具有的 IAP,然后调用适当的恢复方法。
- (IBAction)iapRestorePurchaseButton:(id)sender
{
// When the restorePurchase button is tapped, we will run a few tests.
if (([[NSUserDefaults standardUserDefaults] boolForKey:@"FullVersion100Entries"]) && (![[NSUserDefaults standardUserDefaults] boolForKey:@"FullVersionUnlimitedEntries"]))
{
[self.e100EntriesPurchase restoreThePurchase];
NSLog(@"100 yes but unlmited no restore!!!!!!!!!!!!!!!!!!!!!");
}
else if ((![[NSUserDefaults standardUserDefaults] boolForKey:@"FullVersion100Entries"]) && ([[NSUserDefaults standardUserDefaults] boolForKey:@"FullVersionUnlimitedEntries"]))
{
[self.eUnlimitedEntriesPurchase restoreThePurchase];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Restore Unsuccessful" message:@"Your Apple ID doesn't have an active purchase for upgrading to Pro. " delegate:nil cancelButtonTitle:@"Thanks" otherButtonTitles:nil, nil];
[alertView show];
}
}
因此,当我删除并重新安装应用程序时,我将面临UIAlertView,因为 NSUserDefaults 不会设置为任何内容。
我不知道具体该怎么做,但我怀疑当我购买时,我不仅需要购买NSUserDefault,还需要保存某种收据?
关于这个问题的任何指导都会非常有帮助。
【问题讨论】:
-
你卖什么样的产品?从你的代码看,它好像是消耗品?
-
对不起,我应该把它添加到问题中,现在我会更新它。非消耗品
标签: ios objective-c iphone in-app-purchase restore