LANGUAGE ACQUISITION METHOD FOR iOS SETTING INFORMATION AND COUNTRY

Asked 2 years ago, Updated 2 years ago, 113 views

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 ?

ios swift objective-c swift2

2022-09-30 18:59

2 Answers

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


2022-09-30 18:59

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.


2022-09-30 18:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.