-1
webView変数はnilです。swift - appdelegateでuiviewcontrollerメソッドを呼び出す方法
致命的なエラー:予期せずシングルトンオブジェクトを使用する方法をオプション値
をアンラップしながら、nilを見つけますか?
class PushHandler: NSObject, UAPushNotificationDelegate {
func receivedNotificationResponse(_ notificationResponse: UANotificationResponse, completionHandler: @escaping() -> Swift.Void) {
print("The user selected the following action identifier:%@", notificationResponse.actionIdentifier);
if let targetUrl = notificationResponse.notificationContent.notificationInfo["url"] {
let viewController:MCKWebViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "MCKWebViewController") as! MCKWebViewController
// .instantiatViewControllerWithIdentifier() returns AnyObject! this must be downcast to utilize it
self.window?.rootViewController?.present(viewController, animated: false, completion: nil)
viewController.goURL(targetUrl as! String)
}
completionHandler()
}
class MCKWebViewController: UIViewController {
@IBOutlet weak var webView: UIWebView!
func goURL(_ targetUrl: String) {
let url = URL(string: targetUrl)
let urlRequest = URLRequest(url: url!)
webView.loadRequest(urlRequest)
}
}
後
_ = viewController.view
を追加しようとする問題は何ですか?あなたのエラーはどこで発生しましたか? – MingebagwebView.loadRequest(urlRequest) webViewはnilです。 致命的なエラー:予期せず見つかったnilオプション値をアンラッピング中 –