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:
- Easily preview Mermaid diagrams
- Live update when editing in your preferred editor
- Capture screenshots with customizable margins
- 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]);