ios - NSLocale 在 iOS 11 中返回错误值

标签 ios localization ios11 nslocale

从 iOS 11.0 开始,以下代码返回 "de_US"而不是 "en_US":

// => Returns "de_US"
NSString *regionCode = [[NSLocale currentLocale] objectForKey:NSLocaleIdentifier];
NSLog(@"Region code: %@", regionCode);

在 iOS 11 以下,它返回“en_US”。

我的设备有英语/美国的语言和地区。 首选语言(尽管我没有在我的代码中使用它们)按顺序排列:

  1. 英语
  2. 德语
  3. 法语

这是 iOS 11 的已知问题吗? API 有变化吗?

最佳答案

找到了!

这是从 iOS 11 开始的改变行为。

Under iOS 11, [NSLocale currentLocale] only returns languages supported by your app’s localizations. If your app only supports English (as the base localization), then no matter what language the user selects on the device, currentLocale will always return English.

Under iOS 10 and earlier, currentLocale would directly represent the user’s chosen language and region, regardless of what localizations your app supports.

更多信息在这里:

关于ios - NSLocale 在 iOS 11 中返回错误值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47676897/

相关文章:

ios - "Missing argument parameter ' 队列 ' in call"

ios - 如果我使用 CallKit 框架检查正在进行的通话状态,即使我的应用程序没有任何 VOIP 功能,我的应用程序是否会被拒绝?

java - Struts 2消息资源查找问题

xcode - iPhone X 中的导航栏问题?

uinavigationbar - iOS 11 导航栏中的搜索栏

ios - 导航图标在带有 xcode 9 的 ios 11 中不显示?

ios - 如何使用可选 func textViewDidEndEditing(textView : UITextView) to change text as it's entered?

iphone - 如何从应用程序委托(delegate)、 Storyboard、iOS6 获取我的 View Controller 的实例

ios - 我删除了 Xcode 中的本地化,然后我无法添加任何本地化

objective-c - 如何使用cocoa获取MAC OS ISO 639-2格式的系统语言?