2

For an app that is yet to be first-released, it is easy to figure out how to detect first-launch: look for absence of a "wasLaunched" Bool, or a version number, in the UserDefaults. And then set its value. This is asked-and-answered in several places on StackOverflow.

But... I am updating an already-existing app that did not save any UserDefaults info (of any kind) in its first version. Is there any way to detect, on launch of the new version, that a previous version has existed and run? I can't think of one, but that doesn't prove much.

This is important because the new version charges money for some features that used to be free. I would prefer that earlier users not be suddenly faced with loss of fuctionality.

This was also previously asked (Detecting the first launch of an app with previous versions) but all the answers missed the point of the app already existing.

Note that writing to UserDefaults is not foolproof either. If a user deletes the app before re-installing or upgrading, the UserDefaults will vanish. However, that's an edge case I would be OK with ignoring.

Andrew Duncan
  • 3,553
  • 4
  • 28
  • 55
  • To clarify: you want to retain the old app behavior for users that installed the old version, but apply new behavior if they did not? – nathangitter Oct 20 '17 at 16:54
  • Is your update going to use in-app purchases to start charging for something that used to be free? – rmaddy Oct 20 '17 at 17:53
  • Does the old version of your app save any data anywhere in the app's sandbox? – rmaddy Oct 20 '17 at 18:00
  • Answer to the first two questions is yes. Answer to the third question is: the app does cache some stuff in /temp but not guaranteed to be there. I may have to use that as a best-guess though. – Andrew Duncan Oct 20 '17 at 18:22
  • Your task is really the same as https://stackoverflow.com/questions/19390810/change-paid-app-to-free-but-know-if-user-previously-purchased-it with the same solution. Checking for "first launch" is not what you should be checking. – rmaddy Oct 20 '17 at 20:18
  • I agree that I don't want to check "first launch" per se. Badly worded. Should be something like "did-earlier-version-exist-on-device-before-this-version". (After and including this version we put a stamp in UserDefaults. Like we should have in the first place.) But now to your link: good one! But will a receipt contain original "purchase" info if the app was free? – Andrew Duncan Oct 20 '17 at 22:06
  • It should. The price doesn't change the fact that the user "purchased" the app on a specific date and at a specific version of the app. – rmaddy Oct 20 '17 at 23:20
  • Yep, examination of the receipt reveals the "original_application_version" key-value pair. Thank you so much. (I had perused the receipt structure before but obviously didn't retain, heh.) If you would like, you should post a full-on answer (which would just go to aforementioned link) and I will be happy to mark it as a correct answer. – Andrew Duncan Oct 20 '17 at 23:28

1 Answers1

2

Based on your answer to the first few questions in the comments, the question you posted really should be rewritten to something like:

I currently have a free app. In the next update I wish to make some of the currently free functionality into paid functionality using in-app purchases. However, I don't wish for any existing users of the app to have to pay for the functionality they have been using already. Only new users of the app starting with this update should have to pay for the in-app purchase. How can implement my updated app so that downloaders of the previous version of the app do not have to pay?

Given this, your question has nothing to do with any sort of "first launch" detections. Your need is to see if the user "purchased" (or downloaded) the previous version of your app.

This can be accomplished by performing receipt validation. Once you obtain and verify the receipt, you can inspect the receipt and obtain an original purchase date and original purchase version. If that version is a version prior to adding the paid in-app purchase, treat the user as if they have made the in-app purchase already and show them the paid functionality of your app. Otherwise, check the receipt to see if it includes data on the in-app purchase and give user access as appropriate.

rmaddy
  • 314,917
  • 42
  • 532
  • 579