从 iOS 11.0 开始,以下代码返回 "de_US"而不是 "en_US":
// => Returns "de_US"
NSString *regionCode = [[NSLocale currentLocale] objectForKey:NSLocaleIdentifier];
NSLog(@"Region code: %@", regionCode);
在 iOS 11 以下,它返回“en_US”。
我的设备有英语/美国的语言和地区。 首选语言(尽管我没有在我的代码中使用它们)按顺序排列:
- 英语
- 德语
- 法语
这是 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/