The best way to determine if my application has been updated


I have an IOS app, and each time it is updated I want to do some house cleaning. What is the best way to determine if an IOS app has been updated?

The simplest way may be to get the current version, compare the version to a saved version (if there is one), perform clean up if necessary, save the new version. Here are examples on retrieving and storing version info 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 are wondering how to compare versions here is an example using the NSNumericSearch compare option: