如何首次检查应用程序是否已安装或正在安装 [英] How can I check whether an application has already been installed or is being installed for the first time

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

问题描述

首次检查该应用程序是否已安装或正在安装的最佳方法是什么。

What will be the best way to check that application is already installed or being installed for the first time.

推荐答案

捆绑包版本并将其保存在用户默认值中。

Bundle version and saving it in user defaults.

编辑:

此处有三点需要注意。


  1. 捆绑版本:这是您要发布的应用程序的版本。

  1. Bundle version: This is the version of the your application that you want to release.

旧版本:这将指示您的应用程序的先前版本。我们将其存储在用户默认值中,以便我们在更新应用程序时知道旧版本的内容。如果你的捆绑版本是1.0,这显然是零。

Old version: This will indicate previous version of your application. We will store this in user defaults so that we will know what was the old version when updating our application. This will obviously be nil if your bundle version is 1.0.

目标版本:这表示用户定位的版本。我们稍后会讨论这个问题。

Target version: This indicates the version the user is targeting. We will discuss this later.

因此,条件如

bundleVersion> oldVersion

if(isVersionBetter:myBundleVersion thanVersion:oldVersion)

或者意味着我们要创建我们的数据库(在这种情况下,捆绑版本将是1.0,旧版本将是nil)或更新我们的数据库(在这种情况下,bundle版本将大于1.0,因此旧版本不会是nil)。

would either mean we want to create our database (in this case bundle version would be 1.0 and old version will be nil) or update our database (in this case bundle version would be something greater than 1.0 and hence old version would not be nil).

因此,正如我们所看到的,创建数据库意味着用户是第一次安装应用程序。更新数据库意味着用户已经安装了应用程序并正在更新数据库。

Thus, as we can see, creation of database means user is installing app for the first time. Updating database means user has already installed the app and is updating the database.

但是,如果您想更新应用程序并希望保留数据库原样。也就是说,只有UI更新。

But, there might also be a case when you want to update your app and want to keep the database as it is. That is, only UI updating.

这里,目标版本出现了。

Here, target version comes into picture.

如上所述,目标version是用户定位的版本。如果用户定位捆绑包版本,则所有操作都与上述相同。但是如果用户的目标是捆绑版本之外的其他版本,我们会跳过数据库更新部分,从而只允许更改UI。

As mentioned above, target version is the version the user is targeting. All would work same as above if user is targeting the bundle version. But if user is targeting some other version than bundle version, we would skip database updating part, thus allowing only the UI to change.

所以,最后的陈述将是像这样:

So, the final statement would be something like this:

if( bundleVersion == targetVersion AND bundleVersion > oldVersion ) {
// Either create or update the database.
}else {
// Do nothing. Skips database updating and allows UI update.
}

因此,您的数据库函数看起来像这样

Thus, your database function would look something like this

-(void) initWithTargetVersion:(NSString *) targetVersion {

    NSString *oldDatabaseVersion = [[NSUserDefaults standardUserDefaults] stringForKey:@"OldDatabaseVersion"];
    NSString *bundleDatabaseVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];


    if([bundleDatabaseVersion isEqualToString:targetVersion] && [self isVersionBetter:oldDatabaseVersion new:targetVersion]) {
        // Create or update the database.
    }else {
        // Do nothing.
    }
}

用户将按如下方式传递目标版本:

where user would pass the target version as follows:

[[DatabaseManager sharedManager] initWithTargetVersion:@"1.0"];

这篇关于如何首次检查应用程序是否已安装或正在安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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