这是我的问题。在我打开应用程序之前将我的应用程序存档并安装到我的Iphone之后,我检查设置并看到设置包没有更新。它只显示默认输入(如下图所示)。
我希望它显示更新的设置(如下所示)。
这是我的AppDelegate.m中的代码
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// refresh upload queue
_uploadQueue = [[SCUploadQueue alloc] init];
[_uploadQueue refreshUpload];
return YES;
}
-(void) updateVersionInfo{
// Get Settings.bundle object
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// Get values from .plist file generated by build phase script
NSString *versionNumber = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleShortVersionString"];
// Dealing with the date
NSString *dateFromSettings = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBuildDate"];
// Create the version number
NSString *versionNumberInSettings = [NSString stringWithFormat:@"%@", versionNumber];
NSLog(@"Version: %@", versionNumberInSettings);
NSLog(@"Build date: %@", dateFromSettings);//buildDate);
// Set the build date and version number in the settings bundle reflected in app settings.
[defaults setObject:versionNumberInSettings forKey:@"version"];
[defaults setObject:dateFromSettings forKey:@"buildDate"];
}
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// refresh upload queue
_uploadQueue = [[SCUploadQueue alloc] init];
[_uploadQueue refreshUpload];
return YES;
}
-(void) updateVersionInfo{
// Get Settings.bundle object
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// Get values from .plist file generated by build phase script
NSString *versionNumber = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleShortVersionString"];
// Dealing with the date
NSString *dateFromSettings = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBuildDate"];
// Create the version number
NSString *versionNumberInSettings = [NSString stringWithFormat:@"%@", versionNumber];
NSLog(@"Version: %@", versionNumberInSettings);
NSLog(@"Build date: %@", dateFromSettings);//buildDate);
// Set the build date and version number in the settings bundle reflected in app settings.
[defaults setObject:versionNumberInSettings forKey:@"version"];
[defaults setObject:dateFromSettings forKey:@"buildDate"];
}
当我从xcode构建它时,设置有效。但它不适用于归档。如果您需要更多信息,请告诉我。
答案 0 :(得分:3)
您可以使用构建阶段运行脚本来完成此任务。
注意:在此示例脚本中,项目Root.plist的路径可能不同。此外,需要更改PreferenceSpecifier的索引以匹配Root.plist文件的设置。
version=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}")
build=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
/usr/libexec/PlistBuddy "$SRCROOT/Settings.bundle/Root.plist" -c "set PreferenceSpecifiers:1:DefaultValue $version"
/usr/libexec/PlistBuddy "$SRCROOT/Settings.bundle/Root.plist" -c "set PreferenceSpecifiers:2:DefaultValue $build"