Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default language before the app starts for the first time in iOS/Swift

I wanna set another language as default when the app starts for the first time. iOS doesn't not have this language as an interface language, so my only way is to set it manually. I've found dozens of solutions on SO, and those that work, ONLY work in simulator and not on a real device. Here's what I've tried:

First of all, the way to set the app's language is:

UserDefaults.standard.set(["xx-XX", "yy-YY"], forKey: "AppleLanguages")

The thing is, that this needs the app to be restarted, while I want it to be set the first time the app starts. I've also tried:

UserDefaults.standard.register(defaults: ["AppleLanguages": ["xx-XX", "yy-YY"]])

and even calling UserDefaults.standard.synchronize() which in most cases is not needed at all.

And the places I've tried putting this code:

  1. application(:didFinishLaunchingWithOptions:)
  2. application init :|
  3. Subclassing UIApplication, creating main.swift and adding the above codes as top level statements

And in info.plist:

  1. Setting Localization native development region to xx-XX
  2. Setting the first element of Localizations to xx-XX

By the way, implementing custom localization is not an option at this point in time.

And what confuses me the most, is why such a feature works in simulator and not a real device.

EDIT: I even deleted the default english language, and adding English (World) again, so that there was no Development Language label beside it. Still didn't work.

like image 600
Milad.Nozari Avatar asked Oct 15 '25 04:10

Milad.Nozari


1 Answers

On Xcode next from the Start Stop Buttons you can press the "projectName" -> Edit Scheme... -> Run -> Options and change in Application Language

enter image description here

like image 149
Vasilis D. Avatar answered Oct 17 '25 17:10

Vasilis D.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!