I want to read the original application version from the app's receipt.
In development the app contains no receipt since it's not installed from the store. I need to start a SKReceiptRefreshRequest
in order to get a sandbox receipt. But that prompts the user to log in.
So here's the question: If the app is downloaded from the Store in production, is it guaranteed to contain a receipt? Because if not I would need to start a refresh request, which prompts the user for their credentials. And I don't want to do that without context.
If it's not available, what are best practices for this case? Incorporate the SKReceiptRefreshRequest
into the "restore purchases" routine?
PS: The app is only available on iOS 9+.
Edit
When is iOS app receipt not available? Here's one scenario where the app receipt will be missing. If a user purchases your app from iTunes on a computer (a non-iOS device) and then later syncs that app to their device, there will not be an app receipt.
See this WWDC 2014 video starting at about 48:30
2nd Edit
Another situation where the app receipt will be missing is when a user restores to a new device. App receipts are device specific and will need to be refetched for the new device.
Original Answer
I am in the process of switching an app from paid to freemium so I also need the original application version. I don't know the answer to your "is it guaranteed to be there" question but here is how I decided to handle it.
At startup I look for a previously persisted original application version. If that does not exist yet (this is probably the first launch) I check for the network. If that's fine I check for the app receipt. If it's there I send it to the app store for validation and, if successful, grab the original application version out of the response and persist it. On subsequent launches that persisted value is there so I don't do the receipt validation again. If the app receipt is not present at startup I do not request a receipt refresh. I agree with you, there is no context at this point.
I'm guessing that this will work in all cases where the network is reachable but I do another check at the point of the IAP. Like this...
┌────────────┐
│ Tap Add │
└────────────┘
│
┌───────────────────────────────────────────────────────┤
│ │
│ ▼
│ ┌────────────────────┐ ┌──────────────────────┐
│ ┌──Don't Know─────────────────│ Pre-IAP customer? │───Yes─────────▶│ Create new thing │
│ │ └────────────────────┘ └──────────────────────┘
│ │ │
│ │ │ ┌──────────────────────┐
│ │ └──────No─────────────────▶│ IAP │
│ │ └──────────────────────┘
│ │
│ ▼ ┌────────────────────────────────────────┐
│ ┌──────────────────────┐ │Maybe: Allow one grace thing. Warn that │
│ │ Network Reachable? │────No──────▶│ the user must connect to the internet │
│ └──────────────────────┘ │ before adding another thing. │
│ │ └────────────────────────────────────────┘
│ Yes
│ │
│ ▼ ┌────────────────────────────────────────────────────┐
│ ┌──────────────────────┐ │ Maybe, depending on your requirements: Alert the │
│ │ Receipt Present? │────No──────▶│user that the app receipt is not present and the app│
│ └──────────────────────┘ │ store may ask for their credentials. │
│ │ └────────────────────────────────────────────────────┘
│ Yes │
│ │ ┌─────────────┘
│ ▼ ▼
│ ┌──────────────────────┐ ┌────────────────────────┐
│ │ Valid? │◀────────────│ Refresh the receipt. │
│ └──────────────────────┘ └────────────────────────┘
│ │
│ └─Yes───┐
│ ▼
│ ┌───────────────────────────────────────┐
└──│ Persist original_application_version │
└───────────────────────────────────────┘
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With