KP26
KP26

Reputation: 283

NSLocale is not returning correct Language code

I'm trying to get device current selected language code by using the code below.

NSString *language = [[NSLocale preferredLanguages] objectAtIndex:0];

This line works fine for the first time after installation. When I change the device language from device setting, then I'm trying to retrieve device language that time NSLocale returns previously selected language.

Help to resolve this.

Upvotes: 0

Views: 1627

Answers (2)

KP26
KP26

Reputation: 283

I solved this issue by this line

NSString *identifier = [[NSLocale autoupdatingCurrentLocale ] localeIdentifier];

Swift :

let identifier = NSLocale.autoupdatingCurrent.localeIdentifier

Upvotes: 0

Ladislav
Ladislav

Reputation: 7283

You should get it with

let currentDeviceLanguage = Locale.current.languageCode

or Objective-C

NSString *languageCode = [NSLocale currentLocale].languageCode;

Upvotes: 1

Related Questions