iOS:有没有办法伪造用户的语言环境? [英] iOS: Is there any way to fake the user's locale?

查看:97
本文介绍了iOS:有没有办法伪造用户的语言环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣允许我的用户选择我的应用程序显示给他们的语言/语言环境。我已经想出如何加载正确的包,选择正确的字符串文件等。但是,我仍然使用一些系统项目似乎无法控制。例如,切换控件。

I'm interested in allowing my users to choose the language / locale my app appears to them in. I have figured out how to load the right bundle, choose the correct strings files, etc. However, some system items I still seem to have no control over. Switch controls, for example.

我有什么办法告诉系统这个应用程序现在应该使用特定语言,而不是用户当前的系统设置吗?

Is there any way for me to tell the system that this app should now behave in a specific language, rather than the user's current system setting?

推荐答案

最简单的方法是通过 NSUserDefaults :区域设置由 AppleLocale (区域设置ID为字符串),语言由 AppleLanguages 中的第一个匹配项确定(语言ID数组);您的应用只能为您的应用覆盖这些默认值。要检查它是否被您的应用覆盖,您可以使用类似 [defaults persistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]] objectForKey:@AppleLocale] 。要删除覆盖,请使用 -removeObjectForKey:

The least hacky way is via NSUserDefaults: The locale is determined by AppleLocale (the locale ID as a string) and the language is determined by the first match in AppleLanguages (an array of language IDs); your app can override these defaults for your app only. To check if it's overridden by your app, you can use something like [defaults persistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]] objectForKey:@"AppleLocale"]. To remove the override, use -removeObjectForKey:.

无论您采用哪种方式,您都可能需要更改语言时重新启动应用; OS X和iOS应用程序根本不是为了在运行时更改语言而设计的(在OS X上,只有新推出的应用程序才能看到语言变化;在iOS上,系统会杀死所有应用程序以更改语言)。

Whichever way you do it, you'll probably have to relaunch the app when changing languages; OS X and iOS apps simply aren't designed to change language at runtime (on OS X, only newly launched apps see the language change; on iOS the system kills all apps to change language).

我添加了此功能,使开关语言更易于开发/测试;我不知道这是否会使App Store审核流程失败。

I added this feature to make switching languages easier for development/testing; I have no idea whether this will fail the App Store review process.

这篇关于iOS:有没有办法伪造用户的语言环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆