Reputation: 3805
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.
Upvotes: 1
Views: 1471
Reputation: 373
You can accomplish this with a build phase run script.
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"
Upvotes: 3