Eduardo Costa
Eduardo Costa

Reputation: 1994

Locale-specific default settings in XCode / iOS

I have an iPhone application with a Settings.bundle. This bundle has items with defaults that must be locale-dependent (ex: "Metric Units" must be "off" for US and "on" for Brazil and such).

Is there anyway to keep settings' defaults locale-dependent?

Upvotes: 2

Views: 1938

Answers (2)

Matthias Bauch
Matthias Bauch

Reputation: 90117

I had a similar problem some days ago. From what I know it is impossible to have different default values for different regions so I solved it in a different way.

I have a multi-value setting with Default Fahrenheit and Celsius. By default it is set to default, which means that I figure out the unit in code based on the NSLocale setting

Something like this:

- (MBUnit)temperatureUnit {
    MBUnit tmp = [ud integerForKey:MBUDKeyTemperatureUnit];
    if (tmp == MBTemperatureDefaultUnit) {
        MBUnit defaultTemperatureUnit;
        BOOL isMetric = [[[NSLocale currentLocale] objectForKey:NSLocaleUsesMetricSystem] boolValue];
        if (isMetric) {
            defaultTemperatureUnit = MBTemperatureCelsiusUnit;
        }
        else {
            defaultTemperatureUnit = MBTemperatureFahrenheitUnit;
        }
        return defaultTemperatureUnit;
    }
    return [ud integerForKey:MBUDKeyTemperatureUnit];
}

Upvotes: 3

Joseph Tura
Joseph Tura

Reputation: 6360

Have you looked at stringsTable? You may be able to use that for your purpose. Also check out this documentation

What you certainly can do, is set the defaults when the app is first launched (or when the locale changes, for that matter).

Upvotes: 0

Related Questions