MKStoreKit自动更新订阅

我正在使用MKStoreKit来处理自动更新订阅。 我目前正在testing1个月的订阅(testing订阅持续5分钟)。 我购买订阅后,我等待它过期。 一旦到期,我检查订阅是否仍然有效。

[[MKStoreManager sharedManager] isSubscriptionActive:kSubscriptionMonthlyIdentifier] 

这将返回假像我所期望的。 但是,因为它是自动更新的,所以我期望MKStoreKit在这一点上联系Apple重新validation订阅。 也许我正在使用MKStoreKit错误,但根据文档和博客文章,它应该是如此简单:

 //App Delegate [MKStoreManager sharedManager]; //lets me know when the subscription was purchased [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(subscriptionPurchased:) name:kSubscriptionsPurchasedNotification object:nil]; //lets me know when the subscription expires [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(subscriptionFailed:) name:kSubscriptionsInvalidNotification object:nil]; //In a view with subscription feature if([[MKStoreManager sharedManager] isSubscriptionActive:kSubscriptionMonthlyIdentifier]){ //access to subscription feature } //Where the user would purchase the subscription [[MKStoreManager sharedManager] buyFeature:subscriptionId onComplete:^(NSString* purchasedFeature, NSData* receiptData) { ... } onCancelled:^ { ... } 

我的问题是,为什么当苹果的订阅仍然活跃MKStoreKit不让我知道?

该文件说:

为了testing,生产环境和testing环境中的自动可更新订阅之间的行为有一些差异。

续订速度加快,自动更新订阅每天最多更新六次。 这使您可以testing应用程序如何处理订阅续订以及如何处理续订以及如何处理包含间隙的订阅历史logging。

由于到期和更新速率加快,订阅可能在系统开始尝试续订订阅之前到期,在订阅期间留下一小段时间。 出于各种原因,这种失误也是可能的,确保您的应用程序正确处理它们。

你可以尝试:

  1. testing一个较长的订阅期,这样“系统”有更多的时间来续订订阅(6mo = 30min,1y = 1h)?
  2. 运行一个计时器来检查订阅是否在更长时间后更新?
  3. 通过恢复购买强制更新?

另外,在此详细说明,确保您在查看之前没有等待订阅期的六倍以上,因为订阅可以每天只有六次更新一个testing帐户。

我即将开始在自己的应用程序中实现这一点,所以如果遇到相同的情况,我会写回来。

更新:

我读过(在某个地方)自动更新是在应用程序在到期前24小时后启动的时候发生的。 这可能很难在沙盒中复制。 刷新应用收据(> = iOS 7)或重新validation最近购买的收据(<iOS 7)也可能会导致更新。

我已经在github上发布了我的实现供您阅读。