NSLocale在iOS 11中返回错误的值 [英] NSLocale returning wrong value in iOS 11

查看:230
本文介绍了NSLocale在iOS 11中返回错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Starting from iOS 11.0, the following code returns "de_US" instead of "en_US":

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

在iOS 11下面,它返回en_US。

Below iOS 11, it returns "en_US".

我的设备适用于语言和地区英语/美国。
首选语言(尽管我不在我的代码中使用它们)是有序的:

My device has for language and region English / United States. Preferred languages (despite I do not use them in my code) are in order:


  1. 英语

  2. Deutsch

  3. 法语

这是iOS 11的已知问题吗? API是否已更改?

Is it a known issue of iOS 11? Has the API changed?

推荐答案

找到它!

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

It's a change behaviour starting from iOS 11.


在iOS 11下,
[NSLocale currentLocale]仅返回应用程序本地化支持的语言。如果您的应用仅支持英语(作为基本本地化),那么无论用户在设备上选择何种语言,currentLocale将始终返回英语。

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.

在iOS 10和之前,currentLocale将直接代表
用户选择的语言和区域,无论您的应用支持哪些本地化

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

更多信息:

Maddy的堆栈溢出答案: https://stackoverflow.com/a/46206511/1226963

Maddy's stack overflow answer: https://stackoverflow.com/a/46206511/1226963

这篇关于NSLocale在iOS 11中返回错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆