Accessing the Temperature Unit setting in iOS 10

Posted: September 26th, 2016 | Author: | Filed under: iOS, Programming | Tags: , , , , , , , | No Comments »

In iOS 10 Apple added a new dedicated setting for Temperature Unit in the Settings.app under General > Language & Region > Temperature Unit . It lets you switch your preferred unit between Fahrenheit and Celsius:

iOS 10 settings

 

Sadly Apple did not provide a public API for third party apps. Here is how you can access this preference in your app:

1- You first need to expose the NSLocaleTemperatureUnit NSLocaleKey:

FOUNDATION_EXPORT NSLocaleKey const NSLocaleTemperatureUnit;

2- You can now print the temperature unit. The value is one of these 2 strings: ‘Celsius’ or ‘Fahrenheit’.

NSLog(@"NSLocaleTemperatureUnit value: %@", [[NSLocale currentLocale] objectForKey:NSLocaleTemperatureUnit]);