关于ios:使用restoreCompletedTransactions在新设备上的应用购买中恢复/同一设备上已删除的应用中

Restore In App Purchases on New Devices / Deleted Apps on the same device using restoreCompletedTransactions

我在App Store中有一个应用,并且我要带IAPs来解锁新版本中的功能。我已经针对两种非消耗性产品实施了IAP机制,并且所有购买都运行良好。

当用户购买产品时,我设置了一个NSUserDefault标志,然后使用该标志来解锁应用程序中其他位置的功能。

对我来说很好。

我的问题是关于恢复。

我对此有很多疑问,但是我对解决方案还不清楚。

如果用户购买了IAP,它将存储NSUserDefault标志。但是,如果用户使用具有相同Apple ID的其他设备,或者删除并重新安装了该应用程序,则"恢复购买"按钮将不会检测到先前保存的NSUserDefault(可以理解)。

1
2
3
4
5
6
7
- (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,然后调用适当的还原方法。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
- (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,还需要保存某种收据?

任何有关此问题的指导都将非常有帮助。


当用户点击"恢复购买"按钮时,您应该执行以下操作:

1
[[SKPaymentQueue defaultQueue]restoreCompletedTransactions];

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