Question

I was searching for a way to change the iOS device Locale without having to go through the settings and importing some new framework. Just a simple script or so would be great, or even a piece of code. I was wondering if there was something like :

[[NSLocale currentLocale] setLocale:@"WhateverLocale"];
Était-ce utile?

La solution

This may or may not fulfill your needs, but one way to gain programmatic access over the app's current locale is to override the AppleLanguages key in NSUserDefaults. For example, to change to French:

[[NSUserDefaults standardUserDefaults] setObject:@[ @"fr" ]
                                          forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];

The downside to this approach is that you need to close and reopen the app for the change to take effect.

Note, to return to the system default, simply call:

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppleLanguages"];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top