How to change App's Setting Bundle settings before User opens app (only occurs after archiving)

Here is my problem. After I archive my app and install it on my Iphone before I open my app I check the settings and see that the Settings Bundle is not updated. It just shows the default input (as seen in pic below).

I want it to show the updated settings (like below).

Here is my code in my 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"];

    }

The settings works when I build it off xcode. It does not work with archiving however. Let me know if you need more info.

Answers


You can accomplish this with a build phase run script.

Add a run script:
iOS Developer Doc

  1. In the project editor, select the target to which you want to add a run script build phase.
  2. Click Build Phases at the top of the project editor.
  3. Choose Editor > Add Build Phase > Add Run Script Build Phase.

Configure the script
in the Run Script template. Right under the shell input box is where you you add you script.

Example script
You can use PlistBuddy in your script. Here is an example script that utilizes PlistBuddy to pull the CFBundleShortVersionString and the CFBundleVersion from the apps main Info.plist and adds them as the default values in the Settings bundle Root.plist.

Note: In this example script, the path to your projects Root.plist could be different. Also, the index of the PreferenceSpecifier needs to be changed to match the setup of your Root.plist file.

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"

Need Your Help

Development productivity of Ruby on Rails vs. Java in 2009

java ruby-on-rails

I know this has been a hot topic in the past, spawning many flame wars and a tribe-like attitude in the forums. Some years have passed and Java has evolved: we now have more annotations for almost