loading url from scheme not processing first time - appdelegate vs viewcontroller

前端 未结 2 1090
梦毁少年i
梦毁少年i 2021-01-17 07:39

My app is successfully opening and setting the parameters (from URL-scheme i.e. myApp://sometextToPrint) to a variable in the AppDelegate class but whenever I w

2条回答
  •  逝去的感伤
    2021-01-17 08:27

    @SalihanPamuk I think this is due to the appWillEnterForeground() method. UIApplication.willEnterForegroundNotification - This is the first notification posting an app is coming to the foreground.

    As you have already registered an observer for listening to this notification the appWillEnterForeground() method will invoke before the appDelegate's

    application(_ app: UIApplication, open url: URL, options: 
    [UIApplication.OpenURLOptionsKey : Any] = [:]) - method.
    

    Try implementing the appDelegate's

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Do your stuffs here 
    }
    

    Or if you want to show any particular ViewController after opening the app using any URL setup the code for showing that ViewController inside the

    func application(_ app: UIApplication, open url: URL, options: 
    [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    
    // implemet your code here 
    
    }
    

提交回复
热议问题