Reputation:
There is a situation that I am faced with which seems like it has no solution. Here it is: I have an app on App Store. I didn't write any piece of code for this app keeping the upgrade scenario in mind. For all I could imagine, I never that I would be giving out more versions apart from the one I already have on app store. Now, the situation is that I am required to give an upgrade of my app and with in the new code, I am to identify if it is a new install of the latest version or if it is an upgrade from the older version. I don't know how to approach this as I have not coded my first version appropriately for upgrades? Anybody willing to enlighten me.
Upvotes: 0
Views: 488
Reputation: 3551
In appDidFinishLaunching
put a bit of code to save a user default (those get synced to iTunes with the app and last between installs) if it isn't already there (first run and fresh install). Also save which version it is.
Then if it wasn't a fresh install check if the last version saved is the apps current version number.
If the apps version number is bigger it's an upgrade and you now need to save that as the last installer version.
Else it's just the app opening.
Something like this (code untested)
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"alreadyInstalled"]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"alreadyInstalled"];
[[NSUserDefaults standardUserDefaults] setFloat:[[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] floatValue] forKey:@"lastVersionInstalled"];
//.... contact server or something to say it's a fresh install
}
else if ([[NSUserDefaults standardUserDefaults] floatForKey:@"lastVersionInstalled"] < [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] floatValue]){
[[NSUserDefaults standardUserDefaults] setFloat:[[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] floatValue] forKey:@"lastVersionInstalled"];
//The user has just upgraded
}
else {
//It's neither. The app has just been opened again.
}
Though you won't be able to tell things like, if the user deleted it then redownloaded it or is installing it on another device. For more advanced info you'll probably wont to use something like Flurry analytics. http://www.flurry.com/product/analytics/index.html
Upvotes: 1
Reputation: 26400
I am not sure but I think this will help you.
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
will give you the current version of the app. I think you can use this to check your upgradation.
Upvotes: 0