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

前端 未结 2 1117
梦毁少年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:25

    Copy your code from

    func application(_ app: UIApplication, open url: URL, 
        options: [UIApplication.OpenURLOptionsKey : Any] = [:]) 
        -> Bool {
    

    into

    func application(_ application: UIApplication, 
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) 
        -> Bool {
    

    In that method, check the launchOptions. If it contains the url key, grab that value — and return false.

    if let url = launchOptions[.url] as? URL {
        let geturl = url.host?.removingPercentEncoding
        UserDefaults.standard.set(geturl, forKey: "DeepLinkUrl")
        return false
    }
    

提交回复
热议问题