Reputation: 2329
How to detect the upgrade point in objective C ? Is there anyways to detect that app has just upgraded to newer version or update is in progress. ?
My scenario is this consider a user have an application version 1.0 in his device and he's getting update notification and updating the app. Here after the version update app should have to show some app tutorial.
Upvotes: 0
Views: 140
Reputation: 13222
Use NSUserDefaults
to check if app is launching for first time.
//In applicationDidFinishLaunching:withOptions:
BOOL hasLaunchedBefore = [[NSUserDefaults standardUserDefaults] boolForKey:@"AppHasLaunchedBefore_v1.0"];
if(!hasLaunchedBefore) {
//First launch
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"AppHasLaunchedBefore_v1.0"];
}
else {
//Not first launch
}
When you update the app to version 2.0(let's say) modify the above key to AppHasLaunchedBefore_v2.0
. This way for first launch after update, this key will not be present in the NSUserDefaults
making hasLaunchedBefore = NO
. You can take the necessary action.
If required, you can remove the previous version key from the NSUserDefaults
with,
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppHasLaunchedBefore_v1.0"];
You can programmatically get the bundle version of current released app with,
NSString* version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
//Append this to the user default key, AppHasLaunchedBefore_v%@
Hope that helps!
Upvotes: 2