Finding Out What Version Of Your iOS App Was Originally Installed : Part 1 – The Easy Way


So, for whatever reason - lets say that you want to experiment with a free download and IAP monetization model in an existing paid app but you don't want to double charge existing users, or maybe you need to do some clever user defaults or data model updates - you decide that you need to know what version of your app was originally purchased.

So far as I've been able to discover so far, there are basically two ways to go about this. Well, one way, but there are two ways of getting the data. Well, N ways actually, but let's not get all forked up at this point. This is (one possible (partial) implementation of) the easy way.

Assuming you have a receipt (and you may well not, in your dev version at least, in which case you need a bit of SKReceiptRefresh magic) then you can find it in your app's bundle, and (assuming you have some network connectivity, and can talk to it) you can fling it at the App Store servers and they'll parse the binary blob for you and fling back some JSON.

It looks a little like this, only with nicer error handling.



And the NSDictionary you'll get back from calling [obj parseReceiptOnAppStore] (assuming you get anything back at all) looks like this



And there it is, right there, so handy! "original_application_version" = "1.0". There's a whole bunch of other useful stuff along similar lines in there too.

The good thing about doing it this way, of course, is that you can be pretty sure that Apple's servers know how to parse their own receipts and it also contains extra good stuff that you can't get if you do this the hard way.

The drawback is that it relies on you being able to talk to the network, and for the relevant servers to be up, and if you're about to do something like sticking an IAP roadblock in your App, non availability of network resources is a sure way to deliver some truly antisocial UX, so at the very least, you need a backup plan in case you can't get to the App Store.

That would be the hard way, which involves parsing the blob, which is an ASN DER encoded PKCS7 container. Sounds like fun, right ? Find out in part 2, or if you can't wait, whet your appetite with the Receipt Validation Programming Guide.




Codemonkey, iOS developer, neophyte entrepreneur, frequent hat wearer. Founder of Enigmatic Ape (@EnigmaticApe). Recidivist tea drinker. Sound tennis noob with NEVITC. Now available in Twitter, and ADN



Built With Bootstrap
Powered By Wordpress
Coded By Enigmatic Ape