iPhone更新应用程序版本(在设置中) [英] iPhone update application version (in Settings)
问题描述
我有一个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屋!