iPhone更新应用程序版本(在设置中) [英] iPhone update application version (in Settings)

查看:142
本文介绍了iPhone更新应用程序版本(在设置中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何在我的应用程序的设置包中显示应用程序版本修订版?

我有一个iPhone应用程序,将当前版本显示为设置常量(就像Skype一样)。

I have an iPhone application that displays the current version as a Settings constant (just like Skype does).

当我发布应用程序的第一个版本时,我使用此代码设置应用程序设置:

When I released the first version of the application, I use this code to set the app Settings:

- (void)registerDefaultsFromSettingsBundle {
    NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
    if(!settingsBundle) {
        NSLog(@"Could not find Settings.bundle");
        return;
    }

    NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[settingsBundle stringByAppendingPathComponent:@"Root.plist"]];
    NSArray *preferences = [settings objectForKey:@"PreferenceSpecifiers"];

    NSMutableDictionary *defaultsToRegister = [[NSMutableDictionary alloc] initWithCapacity:[preferences count]];
    for(NSDictionary *prefSpecification in preferences) {
        NSString *key = [prefSpecification objectForKey:@"Key"];
        if(key) {
            [defaultsToRegister setObject:[prefSpecification objectForKey:@"DefaultValue"] forKey:key];

        }
    }

    [[NSUserDefaults standardUserDefaults] registerDefaults:defaultsToRegister];
    [defaultsToRegister release];
}

这个工作得很好,花花公子。

And this worked fine and dandy.

我现在面临的问题是,如果您更新应用程序,则不会重写这些默认值(设置),因此不会更新应用程序版本。

The problem I face now is that if you update the application, these defaults (Settings) are nor re-written, so the application version is not updated.

如何在每次安装时强制设置特定设置?

How can I force that an specific Settings is set on every install?

谢谢
Gonso

Thanks Gonso

推荐答案

您可以使用以下运行脚本构建阶段:

You can use the following 'Run Script' Build Phase:

CFBundleShortVersionString=`/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" ${SRCROOT}/YourApp/YourApp-Info.plist`
CFBundleVersion=`/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" ${SRCROOT}/YourApp/YourApp-Info.plist`
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:3:DefaultValue '${CFBundleShortVersionString} (${CFBundleVersion})'" ${SRCROOT}/YourApp/Settings.bundle/Root.plist

您需要做的就是将YourApp替换为您的应用程序名称并设置相应的密钥路径。

All you need to do, is to replace YourApp with your app's name and set the appropriate keypath.

在我的情况下,我在PreferenceSpecifiers数组中有4个项目,我需要设置最后一个项目的值数组,这就是我使用':PreferenceSpecifiers: 3 :DefaultValue'

In my case, I have 4 items in the PreferenceSpecifiers array, and I need to set the value for the last item from the array and that's why I used ':PreferenceSpecifiers:3:DefaultValue'

这篇关于iPhone更新应用程序版本(在设置中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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