Post not yet marked as solved
Post marked as unsolved with 1 replies, 2,773 views
So I've been working at this for a while, and I haven't been able to figure it out.I'm trying to open my app using a custom URL protocol. I've put this in the "URL Types" area of the Info tab for the project. I've set up the handler function in the "AppDelegate.swift" file, and I have written code to construct a URL from the parts of the custom deep link. The thing is, no matter what I do, the code just crashes the app or does nothing.In AppDelegate.swift:func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
var urlString:String = "https://example.com"
print(url.scheme!)
if url.host != "example.com" {
print(url.host ?? "")
urlString += url.host ?? ""
}
print(url.path)
urlString += url.path
print(url.query ?? "")
urlString += url.query ?? ""
print(urlString)
if verifyUrl(urlString: urlString) {
vC.url = URL(string: urlString)!
}
return true
}In ViewController.swift:var url: URL! = URL(string: "https://example.com")!
func loadPage() {
let urlRequest:URLRequest = URLRequest(url: url)
webView.load(urlRequest)
}I have tried:using a Property Observer on the URL variable to call "loadPage()" (causes "Fatal Error: Unexpectedly found nil while unwrapping an Optional value")calling "loadPage()" from "AppDelegate.swift" (same thing)calling "loadPage()" in "viewDidAppear()" (does nothing)Nothing has worked so far.After doing testing, I found that the "Fatal Error" above is from the webView variable, not the URL and not the URLRequest.Any idea why this isn't working?