NSLocale preferredLanguages โ€‹โ€‹always extracts the language 'en'

I am trying to get the correct language on my device (NOT in SIMULATOR) with the following code:

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

And it is always 'en' , but my current language is set to Spanish

Any thoughts why โ€œenโ€ is always extracted, not the current device language?

+4
source share
2 answers

After some research, I found out that key AppleLanguages โ€‹โ€‹have been overwritten. So,

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults objectForKey:@"AppleLanguages"];

He returned a list of dictionaries with overwritten data. I just did this:

NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
NSDictionary * dict = [defaults dictionaryRepresentation];
for (id key in dict) {
    if([key isEqualToString:@"AppleLanguages"]){
        [defaults removeObjectForKey:key];
    }
}
[defaults synchronize];

To delete the entire key and system reset and return the correct list.

+1
source

. .

:

โ†’ โ†’ โ†’ .

+3

All Articles