3
votes

I have got StoreKit to work for auto-renewable subscriptions and can successfully buy and renew subscriptions via the Sandbox. So far, so good.

The problem I am having is that the expiry date being returned by apple seems in-correct.

When first purchasing the subscription, it gives you a receipt response. In this response it gives you expires_date_formatted, this is obtained by querying the receipt or latest_receipt_info part of the response back from apple.

When the subscription has expired, you will get a latest_expired_receipt_info response (this does not appear in regular purchases and only when the receipt has expired).

For whatever reason, the latest_expired_receipt_info has a different date stored inside expires_date_formatted, and its causing me all sorts of headaches.

Usually my app will report that the subscription has expired but when you try to repurchase a subscription, it will say that the subscription is still active.

This seems to imply that the date inside latest_expired_receipt_info is accurate, but there appears to be no way to get that date (unless you intentionally let the subscription expire).

Examples:

receipt (stored) = {
    bid = "myappid.goeshere";
    bvrs = "1.0";
    "expires_date" = 1321365095905;
    "expires_date_formatted" = "2011-11-15 13:51:35 Etc/GMT";
    ...other stuff....
}
latest_expired_receipt_info = {
    bid = "myappid.goeshere";
    bvrs = "1.0";
    "expires_date" = 1321366860000;
    "expires_date_formatted" = "2011-11-15 14:21:00 Etc/GMT";
    ...other stuff...
}

In the above example, we can see that the expires_date_formatted is totally different, one says 13:51, the other says 14:21

In other tests the difference can be anything from a few minutes to ten or twenty minutes.

How do I get the correct expires_date_formatted?

1
I know this is old, but for anyone else ... if your issue here is that your app restricts premium features too early, as opposed to one about reporting the correct date of expiry to the user to pre-warn them, then perhaps it would be better if you use the "status" value to determine if the subscription is still active. 0 = active, anything else = not active. In my app, I verify the receipt with Apple then cache it, I use "status" to determine if the sub is active, a cached receipt will always be active so I use expiry date to know when to fire off a new verification call - Steven Elliott

1 Answers

3
votes

You are testing in sandbox mode and not in production mode.

In this case subscriptions are much shorter: 7-day subscriptions are only 5 minutes and 1-year subscriptions expire after an hour.