AppleLanguages value overrides the value of langua

2019-01-27 09:20发布

I am working on Localization of my app that supports both spanish and English languages.These options are listed in a tableview.On clicking English i am setting the value "en" for the key "AppleLanguages" in NSUserDefaults.So that it can show the content in English.

NSUserDefaults *nsdefault=[NSUserDefaults standardUserDefaults];
            [nsdefault setObject:[NSArray arrayWithObject:@"en"] forKey:@"AppleLanguages"];
            [nsdefault synchronize];

Also at the same time i am trying to fetch the Language programmatically from IOS device which was set at General>>International>>Language manually using code.

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

For the very first time language gives me correct value that has been set.But If i change my option from list like Spanish or English and set value for key "AppleLanguages".It overrides the value of my device setting language.And from then ownwards i dont get the correct value of language under Setting>>International>>Language.

I want that every time i choose the language manually in settings like Francis etc.I should be able to get the newly set language.I even tried to follow the link by apple.

https://developer.apple.com/library/mac/documentation/macosx/conceptual/bpinternational/Articles/ChoosingLocalizations.html

Any help would be appreciated.

1条回答
太酷不给撩
2楼-- · 2019-01-27 10:06

There is not a right way to do that and you should not do that.
You should only rely on the system settings. I gave you one reason for not doing that: all system calls are made with system language. If you force one language such as spanish in an english system and you display a map inside your app you will see all streets etc in english, the same happen if you request reverse geocoding or other system services.

查看更多
登录 后发表回答