Distinguishing between iPhone app upgrade and app new install?

匆匆过客 提交于 2019-12-25 06:32:40

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/5509459/distinguishing-between-iphone-app-upgrade-and-app-new-install

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!