PDA

View Full Version : Metric information from the locale




louden
Jul 16, 2008, 09:50 AM
I'm trying to extract the measurement system from the locale on the iPhone with kCFLocaleMeasurementSystem or kCFLocaleUsesMetricSystem. They keep coming back to me as non-metric, even though I've rebooted the phone into UK/English.

Does anyone know if these constants are working? Or maybe how to use them :rolleyes:



louden
Jul 16, 2008, 10:04 AM
Nevermind...

RTFM! I didn't see you needed to use CFLocaleGetValue to get at those constants. Very cool... You can even play with it in the simulator.


CFLocaleRef currentLocale;
CFBooleanRef usesMetric;
NSString *measurement = [[NSString alloc] init];
currentLocale = CFLocaleCopyCurrent();
usesMetric = CFLocaleGetValue(currentLocale, kCFLocaleUsesMetricSystem);

if (usesMetric == kCFBooleanFalse)
{
measurement = @"Miles";
}
else
{
measurement = @"Kilimoters";

}

grimjim
Jul 18, 2008, 03:16 PM
I didn't know you could do that.

But I should point out that here in the UK, although we use the metric system for pretty much everything else, we still use miles, so it might be better to allow the user to set the units using a preference option.

Just a thought....