区分iPhone应用程序升级和应用程序新安装? [英] Distinguishing between iPhone app upgrade and app new install?

查看:56
本文介绍了区分iPhone应用程序升级和应用程序新安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的情况似乎无法解决.这里是: 我在App Store上有一个应用程序.考虑到升级方案,我没有为该应用程序编写任何代码.据我所能想象的,除了我在应用商店中已经拥有的版本之外,我从来没有给出过更多的版本.现在,情况是我需要升级我的应用程序,并使用新代码进行识别,这是确定它是最新版本的新安装还是旧版本的升级.我不知道如何解决此问题,因为我没有适当地编码第一个版本以进行升级?任何愿意启发我的人.

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.

推荐答案

appDidFinishLaunching中放入一些代码以保存用户默认设置(这些默认设置与应用程序同步到iTunes并在安装之间持续)已经存在(首次运行和全新安装).还要保存它是哪个版本. 然后,如果不是全新安装,请检查最后保存的版本是否为应用程序的当前版本号. 如果应用程序版本号更大,则是升级,您现在需要将其保存为最新的安装程序版本. 否则,这只是应用程序的打开.

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.
    }

尽管您无法说出类似的信息,但是如果用户删除了它,则重新下载它或将其安装在其他设备上. 对于更高级的信息,您可能不会使用Flurry Analytics之类的工具. http://www.flurry.com/product/analytics/index.html

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

这篇关于区分iPhone应用程序升级和应用程序新安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆