How to handle iOS app launch after update?

Is there a way to find out that the iOS application starts after the update?

I think I can save the current version of the application every time I launch the application, for example, in NSUserDefaults , and check this version every time I open the application.

What about the case:

1) The user installs the application version 1.0, but does not start it.

2) The user installs the application version 2.0.

How to handle this case, for example?

Thanks in advance.

+4
source share
5 answers

If you always did what you suggested, save the application version to NSUserDefaults .

And about your other case, if the application does not start with version 1, then it does with version 2, you can just see it as a new installation.

Since your application never started in the first place, you can simply consider it as a new installation. If you do this to keep track of updates in some kind of analytic tool, you will have a problem. But you can use Apple's install and update reports to get the right install and update list.

Just make sure that if you make any updates from any version, you make the code so that you can upgrade from any previous version. Thus, installing verion 4 of 1 will transform any changes for versions 2 and 3.

+2
source

I found the following note in this website from Apple.

When a user downloads an application update, iTunes installs the update in the new application directory. It then deletes user data files from the old installation to the new application folder before uninstalling the old installation. Files in the following directories will be saved during the upgrade process:

  • /Documents
  • / Library

Although files in other user directories may also be moved, you should not rely on them to be present after the upgrade.

In each version that you release, you can put the txt file with a unique name (unique for each version) in one of these directory updates and check the txt file of the previous version the first time you run the application. This should work even if your application did not start between download and initial update.

+2
source

Each time your application starts, after starting the launch process, the following function is called in the appDelegate class:

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

This is the point where you can check the version of the application, perhaps using something like:

 [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] 
+1
source

I think this might be useful: MTMigration controls blocks of code that need to be run once when upgrading the version in iOS apps. This can be anything from data normalization procedures, β€œWhat's New in This Release” screens, or bug fixes.

It is available through CocoaPods: pod 'MTMigration'

Refer to the MTMigration repository on GitHub ( https://github.com/mysterioustrousers/MTMigration ) for use and examples.

 [MTMigration applicationUpdateBlock:^{ /* This code run on every version change. */ }]; [MTMigration migrateToVersion:@"1.0" block:^{ /* This code only run once in version 1.0 */ }]; [MTMigration migrateToVersion:@"2.0" block:^{ /* This code only run once in version 2.0 */ }]; 

If the user was in version 1.0, skipped 2.0 and upgraded to 3.0, then both blocks 1.0 and 2.0 will be executed.

0
source

I'm a bit late to the party, but if this is still a problem, I use the stored boolean value to see if this is the first application launch:

 if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"]) { NSLog(@"First launch"); NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setBool:YES forKey:@"HasLaunchedOnce"]; [defaults synchronize]; } 

Then I can deal with the installation or upgrade, as you already mentioned in your question.

0
source

Source: https://habr.com/ru/post/1494671/


All Articles