如何检测安装或升级的iOS App? [英] How to detect an iOS App installed or upgraded?

查看:149
本文介绍了如何检测安装或升级的iOS App?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,我需要知道用户是第一次安装应用程序还是从App Store升级它。

I am developing an application and i need to know whether user installed the app for the first time or upgraded it from the App Store.

我如何检测是否app首次安装或升级或重新安装?

How can i detect whether app is installed for the first time or upgraded or re-installed?

提前感谢您的回答。

推荐答案

您可以通过将最新的已知版本保存到 standardUserDefaults来区分安装应用程序后的第一次启动,更新后的第一次启动以及其他启动code>。但据我所知,无法检测到重新安装应用程序,因为当从设备中删除应用程序时,所有与App相关的数据也会被删除。

You can differentiate between the first start after installing the App, the first start after an update and other starts quite easily via saving the latest known version to standardUserDefaults. But as far as I know it is not possible do detect a re-install of the App as all App-related data are also removed when the App is deleted from the device.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSString* currentVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
    NSString* versionOfLastRun = [[NSUserDefaults standardUserDefaults] objectForKey:@"VersionOfLastRun"];

    if (versionOfLastRun == nil) {
        // First start after installing the app
    } else if (![versionOfLastRun isEqual:currentVersion]) {
        // App was updated since last run
    } else {
        // nothing changed 
    }

    [[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:@"VersionOfLastRun"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

这篇关于如何检测安装或升级的iOS App?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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