Override AppleLanguages ​​in NSUserDefaults

If I override / modify AppleLanguages ​​in NSUserDefaults, iOS no longer updates the list when the system language changes. If I leave this list unchanged, the first object in the array will always be the system language, however, if I insert a new object with index 0, and then when changing the system language, iOS will not put the new language at the top of the list anymore. Is there a way to change AppleLanguages ​​in NSUserDefaults and still update the system when the system language changes?

Accatyyc's solution works fine, here is the solution if you are using Swift:

  • Create a main.swift file, add the Swift version to the accepted answer:

    NSUserDefaults.standardUserDefaults().removeObjectForKey("AppleLanguages") UIApplicationMain(Process.argc, Process.unsafeArgv, NSStringFromClass(UIApplication), NSStringFromClass(AppDelegate)) 
  • Go to AppDelegate and delete the following line:

     @UIApplicationMain //Removing this tells Xcode to use your main.swift file 
+6
source share
1 answer

I found a solution after trial and error! Removing the entire AppleLanguages ​​key seems to lead to its restoration to what the user set the settings in the application:

 int main(int argc, char *argv[]) { @autoreleasepool { [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppleLanguages"]; return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } } 
+4
source

Source: https://habr.com/ru/post/972501/


All Articles