iPhone 更新应用程序版本(在“设置”中)

标签 iphone settings

Possible Duplicate:
How can I display the application version revision in my application's settings bundle?

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

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

- (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];
}

效果很好。

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

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

谢谢 贡索

最佳答案

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

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 替换为您的应用程序名称并设置适当的 key 路径。

就我而言,PreferenceSpecifiers 数组中有 4 个项目,我需要设置数组中最后一个项目的值,这就是我使用 ':PreferenceSpecifiers:3:DefaultValue' 的原因

关于iPhone 更新应用程序版本(在“设置”中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1311405/

相关文章:

c# - 创建新的设置实例

iphone - 识别圆圈手势以删除注释,如何检测圆圈?

iphone - 仅当用户点击 ImageView 时,才在图像的 UIScrollView 上显示 UIButton Done

iphone - 将图像设为黑白?

iphone - iOS - MPMediaPickerController - 更改 barStyle

iphone - 有没有办法从 iPhone 地址簿 API 获取 "Me"卡?

android-fragments - AndroidX 中的自定义 ListPreference

python - 修改中间件中的 Django 设置变量

python - scrapy startproject不使用指定的TEMPLATES_DIR来生成项目settings.py

c# - 如何使设计器生成的 .Net 应用程序设置可移植