自动续订订阅和应用收据

Auto-renewing subscription and app receipt

我想知道当 IAP 自动续订订阅自动续订时,应用收据是否以及何时自动刷新。文档暗示应用程序收据在购买时更新(续订?)但我在 IAP 沙箱中没有看到此行为:

Information about consumable products and non-renewing subscriptions is added to the receipt when they’re paid for and remains in the receipt until you finish the transaction. After you finish the transaction, this information is removed the next time the receipt is updated—for example, the next time the user makes a purchase.

Information about all other kinds of purchases is added to the receipt when they’re paid for and remains in the receipt indefinitely.

此外,文档状态:

After a subscription is successfully renewed, Store Kit adds a transaction for the renewal to the transaction queue. Your app checks the transaction queue on launch and handles the renewal the same way as any other transaction. Note that if your app is already running when the subscription renews, the transaction observer is not called; your app finds out about the renewal the next time it’s launched.

对我来说,这意味着我可以监控 SKPaymentQueue 以了解已完成的交易,然后检查应用程序收据以查找它们的记录。但我在 IAP 沙箱中并没有看到这一点。在 IAP 沙盒中,我有一个自动续订的自动续订(每个 user/purchase 6 次,正常的沙盒行为)但是要发现续订,我需要手动刷新应用收据.

假设这一切都按照我期望的方式工作,是否有在 IAP 沙箱中测试以触发此行为的最佳实践?

附带说明一下,文档在购买类型及其在收据中的持久性方面不一致 -- 请参阅 my answer to this question.

收据在自动续订结束时在服务器端更新——您可以通过调用服务器端[=12]来确认这一点=]方法。

更新:看到您正在使用 RMStore,我模拟了一些东西以便我可以查看行为。

在我看来,客户端收据正在更新。我的场景:一个月的 AR 订阅(因此在沙盒中更新 5 分钟)。我在 viewDidLoad:

中放入了一些诊断代码
RMAppReceipt *receipt = [RMAppReceipt bundleReceipt];
if (receipt != nil) {
    NSDateFormatter* localDateTime = [[NSDateFormatter alloc] init];
    [localDateTime setTimeZone:[NSTimeZone timeZoneWithName:@"PST"]];
    [localDateTime setDateFormat:@"yyyy.MM.dd HH:mm:ss zzz"];

    for (RMAppReceiptIAP* purchase in receipt.inAppPurchases) {
        NSString* cancellationDate = nil;
        if (purchase.cancellationDate) {
            cancellationDate = [localDateTime stringFromDate:purchase.cancellationDate];
        }
        NSLog(@"Transaction: %@: product %@, original purchase date: %@, expiration date: %@, cancellation date: %@",
              purchase.originalTransactionIdentifier,
              purchase.productIdentifier,
              [localDateTime stringFromDate:purchase.originalPurchaseDate],
              [localDateTime stringFromDate:purchase.subscriptionExpirationDate],
              cancellationDate);
    }

我还在 RMStore 的 paymentQueue:updatedTransactions: 中放置了一个断点,以查看队列是否随着后续的 AR 购买而更新。

然后我购买了一个月的测试产品,验证了交易,然后退出了应用程序。

在随后每隔 5 分钟重新调用应用程序时,我看到 SKPaymentTransactionObserver 方法中的断点被 transactionSate SKPaymentTransactionStatePurchased 击中。日志显示购买的连续添加(仅显示最后一个版本):

2015-05-27 14:27:32.828 StoreKitSandbox[5803:1054853] Transaction: 1000000156919353: product com.foo.StoreKitSandbox.1_month_autorenew_foo, original purchase date: 2015.05.27 14:02:59 GMT-7, expiration date: 2015.05.27 14:07:58 GMT-7, cancellation date: (null)
2015-05-27 14:27:33.350 StoreKitSandbox[5803:1054853] Transaction: 1000000156919353: product com.foo.StoreKitSandbox.1_month_autorenew_foo, original purchase date: 2015.05.27 14:06:02 GMT-7, expiration date: 2015.05.27 14:12:58 GMT-7, cancellation date: (null)
2015-05-27 14:27:33.774 StoreKitSandbox[5803:1054853] Transaction: 1000000156919353: product com.foo.StoreKitSandbox.1_month_autorenew_foo, original purchase date: 2015.05.27 14:11:07 GMT-7, expiration date: 2015.05.27 14:17:58 GMT-7, cancellation date: (null)
2015-05-27 14:27:34.174 StoreKitSandbox[5803:1054853] Transaction: 1000000156919353: product com.foo.StoreKitSandbox.1_month_autorenew_foo, original purchase date: 2015.05.27 14:16:00 GMT-7, expiration date: 2015.05.27 14:22:58 GMT-7, cancellation date: (null)
2015-05-27 14:27:34.637 StoreKitSandbox[5803:1054853] Transaction: 1000000156919353: product com.foo.StoreKitSandbox.1_month_autorenew_foo, original purchase date: 2015.05.27 14:21:04 GMT-7, expiration date: 2015.05.27 14:27:58 GMT-7, cancellation date: (null)
2015-05-27 14:27:35.069 StoreKitSandbox[5803:1054853] Transaction: 1000000156919353: product com.foo.StoreKitSandbox.1_month_autorenew_foo, original purchase date: 2015.05.27 14:26:15 GMT-7, expiration date: 2015.05.27 14:32:58 GMT-7, cancellation date: (null)

你能用这种诊断方法重现吗?