iOS first launch after update

1.8k Views Asked by At

Upon the first launch of my app, i have used NSUser defaults to show an intro of my app.

However, once an update has been issued and installed, i want to show a whats new page on the first launch after update. My issue is that NS user defaults does not reset and everyone will have different launch counts.

I could use this code to work out the software version...

if ([[NSString stringWithFormat:@"Version %@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]]isEqualToString:@"Version 1.0"])
{
// first launch code here
} 

...but how could i then only get the whats new page to appear on the first launch after update rather than every launch?

If any code is required, it would need to be in Objective C as I have not yet begun developing in swift. Thanks in advance for any assistance.

3

There are 3 best solutions below

3
On BEST ANSWER

Use NSUserDefaults to store a boolean value like "hasShowedUpatePopupForVersionXX". Don't forget to set it to YES in case of new installs

//check if popup has been shown 
 if (![[NSUserDefaults standardUserDefaults] valueForKey:@"hasShowedUpatePopupForVersionXX"]) {
     // Set the value to YES   
     [[NSUserDefaults standardUserDefaults] setValue:@YES forKey:@"hasShowedUpatePopupForVersionXX"];
}
3
On

Do a version check of your app and store the current version in NSUserDefaults. Then on launch check to make sure that value matches the current value. If it doesn't, display the content you wish to display then save the NSUserDefaults key to the new value. I wouldn't store a Bool value and would rather store the current version of your app.

How to get the current version

NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
0
On

Using the above codes, I have created a fully working section of code which finds the App version.

If the app version in the NSUserdefaults is not the same, it will complete the segue and update the NSUserdefaults so that it does not run again until the app Updates.

NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];

NSLog(@"App Version is %@",version);

if ([[NSString stringWithFormat:@"Version %@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]]isEqualToString:@"Version 1.0"])
{
    //check if popup has been shown
    if (![[[NSUserDefaults standardUserDefaults] valueForKey:@"appVersion"] isEqualToString:version]) {
                    [self performSegueWithIdentifier:@"showUpdate" sender:self];
        // Set the value to YES
        [[NSUserDefaults standardUserDefaults] setValue:version forKey:@"appVersion"];
    }