In my code, I have a part that creates a new WKWebView
with a specific WKWebViewConfiguration
, which in turn has a WKPreferences
reference. All of this then gets added to the view of the application.
The problem is that up until this point, my code has been running perfectly, with no problems.
Now, for some bizarre reason, when I launch the application, I get
Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffeec686fc0)
on the line when I create a variable for the WKPreferences
.
I am working with Xcode 10.1
, Swift 4
, and I have Alamofire
and NetworkReachability
pods installed. I have tried just creating the WKWebView
without the WKPreferences
, but the error just moves on to the WKWebViewConfiguration
instead.
func createWebView() {
let preferences = WKPreferences() //<-- EXC_BAD_ACCESS
preferences.javaScriptEnabled = true
let webConfiguration = WKWebViewConfiguration()
webConfiguration.preferences = preferences
webConfiguration.allowsInlineMediaPlayback = true
webViewVar = WKWebView(frame: self.view.bounds, configuration: webConfiguration)
webViewVar.uiDelegate = self
self.view = webViewVar
}
override func loadView() {
createWebView()
}
The expected behavior is that the app would launch and show a web page, that doesn't change, specified elsewhere in the code. The actual result is that the app crashes with the EXC_BAD_ACCESS
error upon startup.
let preferences = WKPreferences()
works for me. What happens when you create a new project and use that one line inviewWillAppear()
? – Nudi