我如何知道 iOS 上的默认度量系统(英制或公制)?
我如何知道 iOS 上的默认度量系统(英制或公制)?
如何从设备设置中获取此首选项,以便我知道在我的应用程序中显示什么?
谢谢
How do I know which is the default measure system (imperial or metric) on iOS ?
How do I get this preference from the device settings, so I know what to display in my app ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
NSLocale
可以告诉你:只有三个国家不使用公制:美国、利比里亚和缅甸。后者使用自己的系统,前两者使用英制单位。
苹果文档说(强调我的):
The
NSLocale
can tell you:Only three countries do not use the metric system: the US, Liberia and Myanmar. The later uses its own system, the former two use Imperial Units.
Apples documentation says (emphasis mine):
@DarkDust 对 swift3 的回答
@DarkDust answer for swift3
这是一个快速版本
here's a swift version
对于迅捷3
For swift 3
正如其他人之前提到的,英国混合使用公制和英制单位。
我建议使用 iOS 10 中引入的新
MeassurementFormatter
来处理大多数这些差异:要将距离呈现为本地自然单位中的字符串,请使用:
官方文档:https://developer.apple.com/documentation/foundation/measurementformatter
As others mentioned before, the UK uses a mix of metric and imperial units.
I would recommend using the new
MeassurementFormatter
introduced in iOS 10 which handles most of these discrepancies:To render a distance as a string in local, natural unit, use:
Official documentation: https://developer.apple.com/documentation/foundation/measurementformatter
usesMetricSystem
在 iOS 16 上已弃用usesMetricSystem
is deprecated on iOS 16你可能应该在你的应用程序中有一个设置,让你的用户选择——这就是苹果在天气应用程序中所做的。
如果您想选择一个合理的默认值,您可以查看区域设置。如果是美国,则选择英制,否则选择公制。这是一种启发式方法,有时会出错,但这只是可以更改的默认值。
You should probably just have a setting in your app and let your users choose -- this is what Apple does in the Weather app.
If you want to choose a sensible default you could look at the locale. If it's US, pick imperial otherwise choose metric. It is a heuristic, it will be wrong sometimes, but it's just a default that can be changed.