This question already has an answer here:
- Check if my IOS application is updated 5 answers
I am developing an application and i need to know whether user installed the app for the first time or upgraded it from the App Store.
How can i detect whether app is installed for the first time or upgraded or re-installed?
Thanks for your answers in advance.
For Swift 3
Just for note:
To obtain localized value of any key you should use
CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), "CFBundleShortVersionString" as CFString)
Checkout Swift 3.0 version of code.
Note: Use CFBundleShortVersionString, for checking actual App version checking.
Please store a version in
NSUserDefaults
(per @Nero's answer) for checking (possible) fresh installs and subsequent updates.For checking reinstalls (in the case where stored
version == nil
), exploit iOS 11's introduction of DeviceCheck API which exposes two bits of device specific data which can be set and retrieved by the app, but maintained by Apple and persisted across an uninstall/reinstalls.You can differentiate between the first start after installing the App, the first start after an update and other starts quite easily via saving the latest known version to
standardUserDefaults
. But as far as I know it is not possible do detect a re-install of the App as all App-related data are also removed when the App is deleted from the device.