Best way to determine if my application is updated

I have an iOS app, and every time it is updated, I want to do a house cleaning. What is the best way to determine if an iOS application is updated?

+4
source share
3 answers

The easiest way is to get the current version, compare the version with the saved version (if any), perform a cleanup, if necessary, save the new version. The following are examples of retrieving and storing version information for comparison.

//Getting the application version NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] //Retrieving the saved application version NSString *savedVersion = [[NSUserDefaults standardUserDefaults] stringForKey:@"versionkey"]; //Saving the version [[NSUserDefaults standardUserDefaults] setObject:version forKey:@"versionkey"]; 

And if you're interested in how to compare versions, here is an example using the NSNumericSearch comparison NSNumericSearch : http://spitzkoff.com/craig/?p=148

+12
source

You can save the latest version number in the database table, and then at startup compare this value with the package version number. Get it by doing the following:

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

If the current version is larger than the version of the last seen, clean your home and then update the "last seen" version in the database table to the current version of the package.

+1
source

Joe way is completely perfect. Just to help these users help a little if you have never installed the default version in a previous version or if you want to check if the current version matches the saved version.

 //Getting the application version NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] //Retrieving the saved application version NSString *savedVersion = [[NSUserDefaults standardUserDefaults] stringForKey:@"versionkey"]; if (version == nil || [version isEqualToString:savedVersion]){ //Saving the version [[NSUserDefaults standardUserDefaults] setObject:version forKey:@"versionkey"]; } 
+1
source

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


All Articles