I am trying to open a link sent in my local notification userInfo
in my WKWebView, i already tried several different options of casting Optional to String, but still no luck, i even tried to check typeof variable i am passing, to be sure it's not Optional anymore, but webView.load still produces fatal, this is my final variant, minimized as much as possible to help reproduce whole situation
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
if let userInfo = response.notification.request.content.userInfo as? Dictionary<String,String> {
if let link = userInfo["link"] {
let url = URL(string: link)!
print(type(of: url));
print(url);
let urlRequest = URLRequest(url: url);
ViewController().webView.load(urlRequest)
}
}
completionHandler();
}
still
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
from ViewController().webView.load(urlRequest)
link is just https://google.com
output to console from print is
URL // typeof url
https://google.com // url