Reputation: 283
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
Reputation: 283
I solved this issue by this line
NSString *identifier = [[NSLocale autoupdatingCurrentLocale ] localeIdentifier];
Swift :
let identifier = NSLocale.autoupdatingCurrent.localeIdentifier
Upvotes: 0
Reputation: 7283
You should get it with
let currentDeviceLanguage = Locale.current.languageCode
or Objective-C
NSString *languageCode = [NSLocale currentLocale].languageCode;
Upvotes: 1