且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何以编程方式更改应用程序语言而无需重新启动我的应用程序?

更新时间:2022-11-06 15:28:20

您不能这样做(没有越狱).您应该以某种方式对应用程序进行编码,以便在某些重要信息发生更改时可以重新开始,而无需重新启动应用程序.例如,您可以弹出所有视图控制器并取消分配它们,然后让用户使用正确的语言重新加载它们.

You can't do that (without jailbreaking). You should code your app in a way, that you can start over when some significant information changes, without restarting the app. For instance you could pop all the view controllers and deallocate them and then let the user reload them using the correct language.

但是请注意,通常您不应该那样做.在iOS上,以非常优雅的方式解决了本地化问题.您只需本地化.strings(以及可选的.nib和图像文件),系统就会为您其余的工作.当用户在设置"应用中更改语言时,系统将终止您的应用.下次用户启动该应用程序时,它将加载正确的语言.

Note however, that normally you shouldn't do anything like that. Localization is solved in a quite elegant way on iOS. You just localize the .strings (and optionally .nib and image files) and the system takes care for the rest for you. When the user changes the language in the Settings app, you app will be terminated by the system. The next time the user starts the app, it will load the correct language.