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 anywa开发者_高级运维y to keep settings' defaults locale-dependent?
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];
}
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).
精彩评论