OneSignal-iOS-SDK icon indicating copy to clipboard operation
OneSignal-iOS-SDK copied to clipboard

How to make my AppDelegate subclass code run before the sdk

Open abdulazizSi opened this issue 1 year ago • 1 comments

How can we help?

Hello there My app has Arabic and English language, and I'm doing a little trick to make the app launch with the Arabic language as the default language when the user first launches regardless of the iPhone system language.

So basically I'm subclassing the AppDelegate to override the initializer method to change the app's default language to Arabic using the code provided. It has to be the first code when launching the app otherwise the app needs to be relaunched again to apply changes. everything was fine until I installed the Onesignal SDK, it seems that it runs first and then my code, because of two reasons 1-the Arabic language won't be applied until I relaunch the app again. 2-if I uninstalled the SDK everything works fine again,

So how can I overcome this issue?

here is my AppDelegate subclass:

class MyApplication: UIApplication {
    override init() {
        print("MyApplication")

        let notFirstOpenKey = "notFirstOpen"
        let notFirstOpen = UserDefaults.standard.bool(forKey: notFirstOpenKey)
        if notFirstOpen == false {
            UserDefaults.standard.set(["ar"], forKey: "AppleLanguages")
            UserDefaults.standard.set(true, forKey: notFirstOpenKey)
        }

        super.init()
    }
}

UIApplicationMain(
    CommandLine.argc,
    CommandLine.unsafeArgv,
    NSStringFromClass(MyApplication.self),
    NSStringFromClass(AppDelegate.self)
)

I'm installing the SDK using Swift Package Manager.

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

abdulazizSi avatar Dec 19 '22 20:12 abdulazizSi

@abdulazizSi Hi dear, Do you have any solution for this problem? I need it.

ehsan-askari avatar Feb 28 '23 12:02 ehsan-askari