Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override AppleLanguages in NSUserDefaults

If I override/alter the AppleLanguages in NSUserDefaults, iOS does not update the list anymore when the system language is changed. If I leave the list unchanged, the first object in the array will always be the system language, however, if I insert a new object at index 0 and later on change the system language, iOS will not put the new language on the top of the list anymore. Is there a way to alter AppleLanguages in NSUserDefaults and still have the system update the list when the system language changes?

The solution from Accatyyc works excellent, here is the solution if you are using Swift:

  1. Create a main.swift file, add the Swift version of the code in the accepted answer:

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

    @UIApplicationMain //Removing this tells Xcode to use your main.swift file
    
like image 358
Jorn Avatar asked Jul 19 '14 13:07

Jorn


1 Answers

I found a solution after some trial and error! Removing the whole AppleLanguages key seems to restore it to what the user has set in the settings application:

int main(int argc, char *argv[])
{
    @autoreleasepool {
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppleLanguages"];
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}
like image 138
Accatyyc Avatar answered Sep 28 '22 14:09

Accatyyc