5 Replies
      Latest reply: Jan 18, 2017 1:54 PM by eskimo RSS
      RetepV_1st Level 1 Level 1 (0 points)

        Hi. iOS 10 has a new setting 'Temperature Unit'. Users can choose a temperature unit, independent of their Locale/Region.

         

        I had found this blog post, which explained how to get it's value: http://blog.timac.org/?tag=nslocaletemperatureunit. And it works great. I modified it a little bit so that it would be backwards compatible from iOS8 up to iOS10.

         

        However... When I submitted my app to Testflight, the app was rejected for the reason: "The app references non-public symbols in [app-name]: _NSLocaleTemperatureUnit"

         

        That's rather disappointing, because I know of no other way to find out what the user entered for this setting. I am 100% sure that users WILL change this setting, and then be disappointed that my app only looks at the region to determine if Celcius or Fahenrheit should be used.

         

        Is there any official solution for this predicament?

         

        Please check here what I did: http://stackoverflow.com/questions/39727075/determine-users-temperature-unit-setting-on-ios-10-celsius-fahrenheit

        • Re: iOS 10 Temperature Unit
          eskimo Apple Staff Apple Staff (6,055 points)

          Are you just trying to render a temperature with the user’s preferred units?  If so, take a look at NSMeasurementFormatter.  For example, this code:

          let mf = MeasurementFormatter()
          let t = Measurement(value: 0, unit: UnitTemperature.celsius)
          
          NSLog("%@", mf.string(from: t))
          

          prints:

          • Fahrenheit by default in the US locale

          • Celcius by default in the UK locale

          • Fahrenheit in the UK locale if the user has explicitly overridden it via Settings > General > Langauge & Region > Temperature Unit.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: iOS 10 Temperature Unit
              RetepV_1st Level 1 Level 1 (0 points)

              I tried this code, using Xcode 8.1, with simulator iPhone 7, iOS 10.1:

               

                  NSMeasurementFormatter* mf = [[NSMeasurementFormatter alloc] init];
                  NSMeasurement* t = [[NSMeasurement alloc] initWithDoubleValue:37.0 unit:[NSUnitTemperature celsius]];
                  NSLog(@"%@", [mf stringFromMeasurement:t]);
              
              
              
              
              
              


              It prints:

              • Region: Netherlands, Temperature Unit: Celcius
                • 37°C
              • Regoin: Netherlands, Temperature Unit: Fahrenheit
                • 37°C
              • Region: United States, Temperature Unit: Celcius
                • 98.6°F
              • Region: United States, Temperature Unit: Fahrenheit
                • 98.6°F

               

              And just for good measure ("Fahrenheit in the UK locale if the user has explicitly overridden it via Settings > General > Langauge & Region > Temperature Unit."):

               

              • Region: United Kingdom, Temperature Unit: Fahrenheit
                • 37°C

               

              Just try it... The Temperature Unit is completely disregarded.

               

              EDIT:

               

              Tried it with Xcode 8.2 and iOS 10.2 simulator. No dice.

                • Re: iOS 10 Temperature Unit
                  eskimo Apple Staff Apple Staff (6,055 points)

                  I tried this code, using Xcode 8.1, with simulator iPhone 7, iOS 10.1:

                  Tried it with Xcode 8.2 and iOS 10.2 simulator. No dice.

                  Please try on a real device.

                  Share and Enjoy

                  Quinn “The Eskimo!”
                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                  let myEmail = "eskimo" + "1" + "@apple.com"

              • Re: iOS 10 Temperature Unit
                dwarfland Level 1 Level 1 (0 points)

                Maybe just use the actual sting value of _NSLocaleTemperatureUnit, rather than importing the constant? At least that would circumvent it flagging as use of a private symbol... Not sure of thats ok in the *spirit* of the rule, but yoiu'd adhere to the letter of of, at least

                  • Re: iOS 10 Temperature Unit
                    eskimo Apple Staff Apple Staff (6,055 points)

                    Maybe just use the actual sting value of _NSLocaleTemperatureUnit, rather than importing the constant?

                    This is very bad advice.  Using private APIs is not just a potential App Review pitfall, it also exposes you to compatibility problems down the track.  You really don’t want to go there, especially when there’s a supported solution that works well AFAICT (but perhaps not so well on the simulator).

                    Share and Enjoy

                    Quinn “The Eskimo!”
                    Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                    let myEmail = "eskimo" + "1" + "@apple.com"