相信大家都知道iphone当前显示的语言,总是偏好语言列表中排序第一位的那个。所以想要获取iphone当前正显示的语言,只需要拿到语言偏好列表数组的第一个原始firstObject即可。
偏好语言列表有如下2种获取方式:
注意:前面一部分是偏好语言列表顺序,最后一部分是地区信息; 当前设置为中国区,打印结果如下:
(lldb) po [NSLocale preferredLanguages]
<__NSArrayM 0x28025a8b0>(
en-CN,
pl-CN,
zh-Hans-CN,
ja-CN,
zh-Hant-CN
)
(lldb) po [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]
{
"AppleLanguages":[
"en-CN",
"pl-CN",
"zh-Hans-CN",
"ja-CN",
"zh-Hant-CN"
],
"AddingEmojiKeybordHandled":1,
"MSVLoggingMasterSwitchEnabledKey":0,
"AppleLocale":"en_CN",
"NSInterfaceStyle":"macintosh",
"AKLastCheckInAttemptDate":2019-02-21 09:08:42 +0000,
"com.apple.content-rating.AppRating":1000,
"AppleITunesStoreItemKinds":[
"podcast",
"artist",
"itunes-u",
"booklet",
"document",
"movie",
"eBook",
"software",
"software-update",
"podcast-episode"
]
}
再看看切换地区为圣诞岛的打印结果吧:
(lldb) po [NSLocale preferredLanguages]
<__NSArrayM 0x281438510>(
en-CX,
pl-CX,
zh-Hans-CX,
ja-CX,
zh-Hant-CX
)
(lldb) po [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]
{
"AppleLanguages":[
"en-CX",
"pl-CX",
"zh-Hans-CX",
"ja-CX",
"zh-Hant-CX"
],
"AddingEmojiKeybordHandled":1,
"MSVLoggingMasterSwitchEnabledKey":0,
"AppleLocale":"en_CX",
"NSInterfaceStyle":"macintosh",
"AKLastCheckInAttemptDate":2019-02-21 09:08:42 +0000,
"com.apple.content-rating.AppRating":1000,
"AppleITunesStoreItemKinds":[
"podcast",
"artist",
"itunes-u",
"booklet",
"document",
"movie",
"eBook",
"software",
"software-update",
"podcast-episode"
]
}