iOS 10 adds the ability for the user to set their "Temperature Unit" choice under Settings > General > Language & Region > Temperature Unit.
How can my app programmatically determine this setting so it can display the right temperature unit? I poured through NSLocale.h and didn't see anything relevant.
(Before iOS 10, it was sufficient to test if the locale used metric and assume that metric users want to use Celsius. This is no longer the case.)
Go to Settings > General > Language & Region. Select Temperature Unit and then change it to either Celsius or Fahrenheit, whichever you want to use. Now your iPhone will use that unit by default whenever it needs to show the temperature.
A change of 1 degree Fahrenheit equals a change of 5/9 = 0.56 degrees Celsius. To convert a Fahrenheit temperature to Celsius, subtract 32 and multiply by 5/9. This is the Fahrenheit analog of the Kelvin scale.
Go to Day One > Settings > Advanced > toggle the option for Fahrenheit. Turning this off will enable Celsius. You can also change the weather service used in Day One iOS.
I wrote a little extension for UnitTemperature
to get the unit selected based on the findings from Fábio Oliveira. My use case was knowing which unit the user had selected, not necessarily using it to display something, this is how I did it.
extension UnitTemperature {
static var current: UnitTemperature {
let measureFormatter = MeasurementFormatter()
let measurement = Measurement(value: 0, unit: UnitTemperature.celsius)
let output = measureFormatter.string(from: measurement)
return output == "0°C" ? .celsius : .fahrenheit
}
}
Again, remember to test this using an actual device, not a Simulator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With