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

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

问题描述

我正在开发一个应用程序,我需要知道用户是第一次安装该应用程序还是从 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.

如何检测应用是首次安装还是升级或重新安装?

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

提前感谢您的回答.

推荐答案

您可以通过将最新的已知版本保存到 来轻松区分安装应用程序后的首次启动、更新后的首次启动和其他启动标准用户默认值.但据我所知,不可能检测到重新安装该应用程序,因为当从设备中删除该应用程序时,所有与应用程序相关的数据也会被删除.

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 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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