提问人:Peel 提问时间:10/28/2023 更新时间:10/30/2023 访问量:48
如何判断用户的区域设置单位设置
How to tell user's locale units settings
问:
我正在将我的 iOS 应用程序国际化,以处理美国惯用单位(英制)和 SI(公制)。有没有办法根据用户的区域设置或其他设置信息来判断用户的首选设置是什么?
我要求用户输入数据,并且需要知道在调用时要分配哪个单位。我希望能够为用户分配正确的单位,而无需询问他们的偏好。我知道系统可以使用 处理正确的输出单元。但是输入呢?Measurement()
let weight = Measurement(value: 75, unit: UnitMass.kilograms)
weight.formatted()
我的应用程序非常面向用户数据输入,使用以下方法:UnitType
Measurement Imperial Metric
Length feet meters
Distance miles kilometers
Mass pounds kilograms
Displacement cubicInches liters
Volume gallons liters
Power horsepower kilowatts
Temperature farenheit celcius
AtmosPressure inchesOfMercury millibars
Speed milesPerHour kilometersPerHour
答:
0赞
Mojtaba Hosseini
10/30/2023
#1
您可以为每个单元使用正确的初始值设定项,例如:
let currentMassUnit = UnitMass(forLocale: .current)
请注意,用户可能不喜欢使用其区域设置进行计算。
评论
UnitType