【问题标题】:Restore In App Purchases on New Devices / Deleted Apps on the same device using restoreCompletedTransactions使用 restoreCompletedTransactions 在同一设备上恢复新设备上的应用内购买/已删除的应用
【发布时间】: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


【解决方案1】:

当用户点击“恢复购买”按钮时,你应该这样做:

[[SKPaymentQueue defaultQueue]restoreCompletedTransactions];

新交易将被推送到您的付款队列,状态为“已恢复”,应用应将它们视为任何新购买的交易。

【讨论】:

  • 亲爱的米哈伊尔 - 正如你所说,我删除了 UIAlertView(这表明没有成功的恢复可用)并等待它确实运行并恢复。我现在明白设置 UIAlertView 的原因是因为那时 NSUserDefaults 确实为空。非常感谢您对此的想法,因为我的代码正在运行相同的方法,只是从另一个类中调用,但您的回答帮助我思考:)
猜你喜欢
  • 1970-01-01
  • 2011-12-07
  • 1970-01-01
  • 2012-05-11
  • 1970-01-01
  • 2017-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多