Set default language on first launch of iOS

I try to set the language for my application on first start.

Seeing this question, I decided to do the same.

Setting the default language for the iPhone application on first launch

I adjusted the code a bit and did this:

int main(int argc, char * argv[]) {
    @autoreleasepool {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:@[[ITConf getStringForKey:ITConfLocale]] forKey:@"AppleLanguages"];
        [defaults synchronize];
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([ITAppDelegate class]));
    }
}

But this code does not work (changes were made after the second run). However, the following code runs without any problems:

int main(int argc, char * argv[]) {
    @autoreleasepool {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:@[@"fr"] forKey:@"AppleLanguages"];
        [defaults synchronize];
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([ITAppDelegate class]));
    }
}

I do not understand why. ITConf returns a string from a .plist file:

NSString *fileP = [[NSBundle mainBundle] pathForResource:@"Conf" ofType:@"plist"];
dictionary = [[NSDictionary alloc] initWithContentsOfFile:fileP];
return dictionary[key];

I checked using LLDB and will return NSString with the correct value.

Black magic seems to me!

+4
source share
2 answers

Info.plist RTL RTK .

Set default language

0

, [NSBundle mainBundle], , [NSBundle mainBundle] ( ) AppleLanguages.

0

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


All Articles