I'd like to get language and country information on the settings screen.
For ios9 series
NSLocale.preferredLanguages().first
when used.
"ja-JP" appears.
for ios 8 or lower
"ja" appears.
"As for the information I would like, ""ja-JP"", but how do I ""language-country""
for ios8 and below?"
Is it possible to get ?
Wouldn't it be better to take them out separately and connect them if necessary?
let locale=NSLocale.currentLocale()
let languageCode=locale.objectForKey(NSLocaleLanguageCode) as!String//->ja
let countryCode=locale.objectForKey(NSLocaleCountryCode) as!String//->JP
NSLocale.preferredLanguages()
is originally an API that returns the language code, so NSLocale.currentLocale()
is more appropriate when retrieving device language and regional settings.
See Technical Note TN2418 for changes in language code handling between iOS 8 and iOS 9 and later.
In contrast, currentLocale()
retrieves terminal locale settings, so you can consistently retrieve languages and regions even before iOS 8.
NSLocale.currentLocale().localeIdentifier
can be retrieved using ja_JP
.It is joined by an underbar, not a hyphen.
© 2024 OneMinuteCode. All rights reserved.