Pass custom URL scheme data from AppDelegate to ViewController in Xcode 14

57 Views Asked by At

Custom URL scheme starts my app, this part works! Now I need to pass custom URL scheme data from AppDelegate to ViewController It always be a empty string, why?

in AppDelegate:

    var window: UIWindow?
    var mytr: String!
    
    func application(_ app: UIApplication,
                     open url: URL,
                     options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {

        mytr = "TheData" //just try a string first
        return true
    }

in ViewController

        override func viewDidLoad() {
        super.viewDidLoad()
        self.webView.uiDelegate = self
        
        let appDelegate = UIApplication.shared.delegate as? AppDelegate
        let mypath = appDelegate?.mytr //here mypath always be "" why?
0

There are 0 best solutions below