错误:升级到iOS 9后无法找到.plist文件

时间:2015-09-28 22:18:26

标签: plist ios9

Project在iOS 8设备和模拟器上构建和运行完美。但是在iOS 9设备上运行会出现错误:无法找到Root.plist。 plist将根据首选语言(英语或普通话)进行选择。

NSString *path = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
     path = [path stringByAppendingPathComponent:[[[NSLocale preferredLanguages] objectAtIndex:0]  stringByAppendingPathExtension:@"lproj"]];
     path = [path stringByAppendingPathComponent:@"Root.plist"];

my files in project nav window

1 个答案:

答案 0 :(得分:0)

修正了问题 在先前版本的iOS中,[NSLocale preferredLanguages]返回“en”表示英语,iOS 9返回“en-US”。因此创建的路径错误,找不到文件

 NSString *path = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
    NSString *lang = [[NSLocale preferredLanguages] objectAtIndex:0];

    /*iOS 9 fix as lang for ios 9 returns en-US*/
    if ([lang isEqualToString:@"en-US"]) {
        lang = @"en";
    }

    path = [path stringByAppendingPathComponent:[lang stringByAppendingPathExtension:@"lproj"]];
    path = [path stringByAppendingPathComponent:@"Root.plist"];