Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 如何在用户打开应用程序之前更改应用程序的设置捆绑包设置(仅在存档后发生)_Xcode - Fatal编程技术网

Xcode 如何在用户打开应用程序之前更改应用程序的设置捆绑包设置(仅在存档后发生)

Xcode 如何在用户打开应用程序之前更改应用程序的设置捆绑包设置(仅在存档后发生),xcode,Xcode,这是我的问题。在我归档我的应用程序并在打开应用程序之前将其安装到Iphone上之后,我检查了设置,发现设置包没有更新。它只显示默认输入,如下图所示 我希望它显示更新后的设置,如下所示 这是我在AppDelegate.m中的代码 -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for

这是我的问题。在我归档我的应用程序并在打开应用程序之前将其安装到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构建它时,这些设置就起作用了。但是,它不适用于归档。如果您需要更多信息,请告诉我。

您可以通过构建阶段运行脚本来完成此任务

添加运行脚本:

在项目编辑器中,选择要向其添加项目的目标 运行脚本构建阶段。 单击项目编辑器顶部的“构建阶段”。 选择编辑器>添加构建阶段>添加运行脚本构建阶段。 添加构建阶段>

在运行脚本模板中配置脚本。shell输入框的正下方是添加脚本的位置

可以在脚本中使用的脚本示例。下面是一个示例脚本,它利用PlistBuddy从apps main Info.plist中提取CbundleShortVersionString和CbundLeverVersion,并将它们作为默认值添加到Settings bundle Root.plist中

注意:在这个示例脚本中,项目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"

您可以通过构建阶段的运行脚本来实现这一点

添加运行脚本:

在项目编辑器中,选择要向其添加项目的目标 运行脚本构建阶段。 单击项目编辑器顶部的“构建阶段”。 选择编辑器>添加构建阶段>添加运行脚本构建阶段。 添加构建阶段>

在运行脚本模板中配置脚本。shell输入框的正下方是添加脚本的位置

可以在脚本中使用的脚本示例。下面是一个示例脚本,它利用PlistBuddy从apps main Info.plist中提取CbundleShortVersionString和CbundLeverVersion,并将它们作为默认值添加到Settings bundle Root.plist中

注意:在这个示例脚本中,项目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"

您可以通过构建阶段的运行脚本来实现这一点

添加运行脚本:

在项目编辑器中,选择要向其添加项目的目标 运行脚本构建阶段。 单击项目编辑器顶部的“构建阶段”。 选择编辑器>添加构建阶段>添加运行脚本构建阶段。 添加构建阶段>

在运行脚本模板中配置脚本。shell输入框的正下方是添加脚本的位置

可以在脚本中使用的脚本示例。下面是一个示例脚本,它利用PlistBuddy从apps main Info.plist中提取CbundleShortVersionString和CbundLeverVersion,并将它们作为默认值添加到Settings bundle Root.plist中

注意:在这个示例脚本中,项目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"

您可以通过构建阶段的运行脚本来实现这一点

添加运行脚本:

在项目编辑器中,选择要向其添加项目的目标 运行脚本构建阶段。 单击项目编辑器顶部的“构建阶段”。 选择编辑器>添加构建阶段>添加运行脚本构建阶段。 添加构建阶段>

在运行脚本模板中配置脚本。shell输入框的正下方是添加脚本的位置

可以在脚本中使用的脚本示例。下面是一个示例脚本,它利用PlistBuddy从apps main Info.plist中提取CbundleShortVersionString和CbundLeverVersion,并将它们作为默认值添加到Settings bundle Root.plist中

注意:在这个示例脚本中,项目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"