Forcing a language change notification iOS

筅森魡賤 提交于 2019-12-10 16:34:38

问题


my app is being localized and we are concerned with dialects. (ie. difference between spanish and spanish in peurto rico) I notice that just changing the region doesn't push a notification to the app that will trigger the localization.. only changing the language triggers this notification.

In my app delegate i would like to check to see if the region has changed in my applicationDidBecomeActive method and if it has, i'd like to push the notification that iOS would have pushed if the language had changed.. is that possible?


回答1:


Each time your app returns to the foreground (not when it becomes active), get the current locale. Compare the latest locale to the previous locale. If the new and previous locale are different enough for you, post the notification.

Example - going from Spain to Mexico should change the locale from es_ES to es_MX.

Edit:

To post the notification you can do:

[[NSNotificationCenter defaultCenter] postNotificationName:NSCurrentLocaleDidChangeNotification object:nil];



回答2:


To programatically post the notification:

[[NSNotificationCenter defaultCenter] postNotificationName:NSCurrentLocaleDidChangeNotification object:self userInfo:nil];


来源:https://stackoverflow.com/questions/17324589/forcing-a-language-change-notification-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!