NSLocale 在 iOS 11 中返回错误值

NSLocale returning wrong value in iOS 11

从iOS11.0开始,以下代码returns"de_US"代替"en_US":

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

iOS11以下,returns"en_US".

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

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

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

找到了!

这是从iOS11.

开始的改变行为

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.

这里有更多信息: