覆盖NSUserDefaults中的AppleLanguages

7
如果我在NSUserDefaults中覆盖/更改AppleLanguages,当系统语言更改时iOS将不再更新列表。如果我保持列表不变,则数组中的第一个对象始终是系统语言;但是,如果我在索引0处插入一个新对象,然后稍后更改系统语言,iOS将不再将新语言放在列表顶部。是否有一种方法可以更改NSUserDefaults中的AppleLanguages并仍然使系统在系统语言更改时更新列表?
Accatyyc的解决方案非常出色,如果您使用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
    

我也有同样的问题,你找到任何解决办法了吗? - Accatyyc
在问题中添加答案会让人感到困惑。如果您有自己问题的答案,请在下面发布! - rmp251
1个回答

6
我在尝试了一番后找到了一个解决方案!移除整个AppleLanguages键似乎可以恢复用户在设置应用程序中所设置的语言:
int main(int argc, char *argv[])
{
    @autoreleasepool {
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppleLanguages"];
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接