1

When user login, I am getting its language code from server.

Then I try to force to set this language as follow:

let defaults = NSUserDefaults.standardUserDefaults()
defaults.setObject(["de"], forKey: "AppleLanguages")
defaults.synchronize()

But this change will not reflect immediately.

If I restart the app then it works fine

I also tried to reload root view but still not working

How can I see change immediately?

Thanks for your time :)

Wain
  • 118,658
  • 15
  • 128
  • 151
user2526811
  • 1,233
  • 4
  • 20
  • 54
  • This might help , have you tried this? http://stackoverflow.com/questions/1669645/how-to-force-nslocalizedstring-to-use-a-specific-language/20257557#20257557 – Bhumit Mehta Jul 07 '16 at 06:24

1 Answers1

0

You need to set the language preference in the main() function before the instance of UIAppdelegate is created.

But as you get the language preference only when the user logs in, it will not change the used language at runtime.

So I don't see any way by which you can get it to work immediately after the user logs in other than asking the user to relaunch the App. (Another option is forcefully killing the App, but the would of course be very poor user experience and would also risk a rejection from Apple if the reviewer spots it)

7vikram7
  • 2,764
  • 1
  • 25
  • 43