What will be the best way to check that application is already installed or being installed for the first time.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Bundle version and saving it in user defaults.
EDIT:
There are three things to note here.
Bundle version: This is the version of the your application that you want to release.
Old version: This will indicate previous version of your application. We will store this in user defaults so that we will know what was the old version when updating our application. This will obviously be nil if your bundle version is 1.0.
Target version: This indicates the version the user is targeting. We will discuss this later.
So, condition such as
bundleVersion > oldVersionorwould either mean we want to create our database (in this case bundle version would be 1.0 and old version will be nil) or update our database (in this case bundle version would be something greater than 1.0 and hence old version would not be nil).
Thus, as we can see, creation of database means user is installing app for the first time. Updating database means user has already installed the app and is updating the database.
But, there might also be a case when you want to update your app and want to keep the database as it is. That is, only UI updating.
Here, target version comes into picture.
As mentioned above, target version is the version the user is targeting. All would work same as above if user is targeting the bundle version. But if user is targeting some other version than bundle version, we would skip database updating part, thus allowing only the UI to change.
So, the final statement would be something like this:
Thus, your database function would look something like this
where user would pass the target version as follows: