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:
Want to support this blog? Please check out
- Easily preview Mermaid diagrams
- Live update when editing
- Capture screenshots
- Create PNG from the Terminal
- Free download on the Mac App Store
Sadly Apple did not provide a public API for third party apps. Here is how you can access this preference in your app:
- You first need to expose the
NSLocaleTemperatureUnit NSLocaleKey
:
FOUNDATION_EXPORT NSLocaleKey const NSLocaleTemperatureUnit;
- You can now print the temperature unit. The value is one of these 2 strings:
Celsius
orFahrenheit
.
NSLog(@"NSLocaleTemperatureUnit value: %@", [[NSLocale currentLocale] objectForKey:NSLocaleTemperatureUnit]);