I'm trying to change my WebView URL, but every time I get fatal error: unexpectedly found nil while unwrapping an Optional value
.
What's wrong? Thanks.
@IBOutlet weak var myWebView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
myWebView.delegate = self
let url = NSURL (string: "http://cnn.com");
let requestObj = NSURLRequest(url: url! as URL);
myWebView.loadRequest(requestObj as URLRequest);
}
func changeURL(urlIncome:String) {
let url = NSURL(string: urlIncome)
let requestObj = NSURLRequest(url: url as! URL)
myWebView.loadRequest(requestObj as URLRequest);
}
My AppDelegate
code:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var vc = ViewController()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.statusBarStyle = .lightContent
OneSignal.initWithLaunchOptions(launchOptions, appId: "", handleNotificationReceived: { (notification) in
let payload = notification?.payload
//let fullMessage = payload?.title
if let additionalData = payload?.additionalData, let actionURL = additionalData["url"] as? String {
self.vc.changeURL(urlIncome: actionURL);
}
}, handleNotificationAction: { (result) in
// This block gets called when the user reacts to a notification received
let payload = result?.notification.payload
let fullMessage = payload?.title
NSLog(fullMessage!);
}, settings: [kOSSettingsKeyAutoPrompt : true, kOSSettingsKeyInFocusDisplayOption : false])
// Override point for customization after application launch.
return true
}