Reputation: 147
i tried to set the localization to Arabic by writing the following code :
int main(int argc, char * argv[]) {
@autoreleasepool
{
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"ar-EG", nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
I fetch the AppleLanguages in AppDelegate and make sure it successfully returns ar-EG as the first language in the array but at the first run of the app , the language Direction is still UIUserInterfaceLayoutDirectionLeftToRight
and doesn't change UIUserInterfaceLayoutDirectionRightToLeft
like it does in the second run .
the first run succeed changing the layout direction only on iPhone 6s.
Any ideas guys .
Upvotes: 2
Views: 286
Reputation: 26
Add this in your Appdelegate or Parent View Controller if you have one :
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) {
[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceRightToLeft];
}
And use one of those libraries who localize the languages on the fly and it will work good on iOS 9 (and greater).
Note : for iOS 8, you can add an alert message that tells the user that configuarations will need to take place still and asks him to restart or even preforms "exit(0)" on clicking OK and Remains opened on clicking cancel. But since iOS 9 has the bigger share in market so that won't happen a lot for your app I think.
Upvotes: 1
Reputation: 1102
I have had to resolve similar issues with user selected languages in iOS 6 - 9 - which may be different from your case. My findings were that the only reliable way to consistently force apps into a (new) language across the spectrum of devices was to implement an app restart. i.e quit and restart the app programmatically. In these cases the language choice had to be implemented as a user choice. We got rejected for not running in the device's language at initial launch.
Upvotes: 0