Reputation: 16124
First off, this question pertains to iOS7+ receipts so all the questions/answers on SO which refer to latest_receipt
and latest_receipt_info
are not applicable (as they have been deprecated and are going away). It seems that the bulk of the knowledge base about renewing subscriptions on SO is from 2011 and 2012 so is misleading and providing incorrect information for current specs.
I know when my user's current subscription expires. I want to know if they renewed it or not. According to Apple when their subscription is renewed:
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.
That all makes sense. So now the obvious question, which Apple does not address, is how do I determine if the subscription was renewed if the user does not close the app and relaunch it (which causes StoreKit to send the app the transaction to process)? If the user leaves the app open for a long period of time the transaction will not be received but I can't continue to provide the content because the expiration date has passed. In theory a user could leave the app running for months without relaunching.
Is the answer to call [NSBundle mainBundle].appStoreReceiptURL
to get the receipt myself and then validate it? Will this provide the updated receipt? And then when the transaction arrives from the StoreKit queue on next launch just process that same receipt a second time (since there is no real way to ignore it)? This seems very kludgy. If we have to get the receipt ourselves in some cases, why bother sending it to us via the queue at all?
Any thoughts on the correct workflow?
Upvotes: 4
Views: 867
Reputation: 663
If you verify the device's onboard receipt using Apple's verification URL, the JSON response will contain at key 'latest_receipt_info' an array representing an up-to-date list of transactions for this Apple ID. This list will include any renewals that have taken place since the last time the StoreKit transaction queue was updated. I.e. you can do this at any time, either from the device or from your server, to find out about any renewal/s, and you only need to watch the transaction queue to find out about the user's initial purchase of the subscription.
This SO answer is very helpful concerning the ambiguous language in Apple's docs that seems to have left so many of us confused: https://stackoverflow.com/a/35912565/492075
Upvotes: 1