Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone update application version (in Settings) [duplicate]

Possible Duplicate:
How can I display the application version revision in my application's settings bundle?

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?

Thanks Gonso

like image 919
gonso Avatar asked Aug 21 '09 11:08

gonso


People also ask

Why do I have two settings apps on my iPhone?

You can have duplicate apps on your iPhone as a result of the new iOS 15 update, or due to app installation errors. It is also possible that you are swiping over the App Library and are seeing the same apps as on your home screen, making it seem like these apps are duplicated.

How do you manage app settings on iPhone?

On your iPhone, go to Settings, then tap your name. Tap Password & Security > Apps Using Apple ID. Select the app or developer, then tap Manage Settings.

What is per-app setting on iPhone?

Per-app Accessibility settings let you enable features for specific apps or override your global Accessibility settings.


2 Answers

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

All you need to do, is to replace YourApp with your app's name and set the appropriate keypath.

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'

like image 142
arturgrigor Avatar answered Sep 25 '22 20:09

arturgrigor


I have this code in my application delegate's -applicationDidFinishLaunching:

#if DDEBUG // debugging/testing
    NSString *versionString = [NSString stringWithFormat:@"v%@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
#else
    NSString *versionString = [NSString stringWithFormat:@"Version %@",[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]];
#endif // DDEBUG
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setValue:versionString forKey:@"version"];
    printf("Version: = %s\n", [versionString cStringUsingEncoding:NSMacOSRomanStringEncoding]);
    [defaults synchronize]; // force immediate saving of defaults.

But app has to be run before Settings 'version' updates to reflect the change.

like image 33
westsider Avatar answered Sep 23 '22 20:09

westsider