Question

I am using MKStoreKit to handle autorenewable subscriptions. I'm currently testing a 1 month subscription (in test a subscription lasts 5 minutes). After I purchase the subscription I wait for it to expire. Once it expires I check if the subscription is still active.

[[MKStoreManager sharedManager] isSubscriptionActive:kSubscriptionMonthlyIdentifier]

This returns false like I would expect. However, since it is auto-renewing, I would expect MKStoreKit at that point to contact Apple to revalidate the subscription. Maybe I'm using MKStoreKit wrong, but according to the docs and the blog post it should be as simple as:

//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:^
{
...
}

My question is why, when the subscription is still active on Apple's end does MKStoreKit not let me know?

Was it helpful?

Solution

The documentation says:

For the sake of testing, there are some differences in behavior between auto-renewable subscriptions in the production environment and in the test environment.

Renewal happens at an accelerated rate, and auto-renewable subscriptions renew a maximum of six times per day. This lets you test how your app handles subscription renewal and how it handles a renewal after a lapse and how it handles a subscription history that includes gaps.

Because of the accelerated expiration and renewal rate, the subscription can expire before the system starts trying to renew the subscription, leaving a small lapse in the subscription period. Such lapses are also possible in production for a variety of reasons—make sure your app handles them correctly.

Could you try to:

  1. test a longer subscription period, so that the "system" has more time to renew the subscription (6mo = 30min, 1y = 1h)?
  2. run a timer to keep checking if the subscription renews after an extended period of time?
  3. force renewal by restoring the purchase?

Also, as detailed here make sure you have not waited more than six times the subscription period before checking, as the subscription can renew for a single test account only six times a day.

I'm just about to start implementing this in my own app, so I'll write back if I encounter the same situation.

UPDATE:

I read (somewhere) that autorenewal occurs when an app is launched in the period after 24 hours before expiration. This may be hard to replicate in the sandbox. Renewal can also be forced by refreshing the app receipt (>= iOS 7) or re-verifying the receipt from the most recent purchase (< iOS 7).

I've posted my implementation on github for your perusal.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top