可能的重复:
如何在应用程序的设置包中显示应用程序版本修订? https://stackoverflow.com/questions/877128/how-can-i-display-the-application-version-revision-in-my-applications-settings
我有一个 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 替换为您的应用程序名称并设置适当的密钥路径。
就我而言,PreferenceSpecifiers 数组中有 4 个项目,我需要设置数组中最后一项的值,这就是我使用 ':PreferenceSpecifiers: 的原因:3:默认值'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)