Reputation: 7524
I implemented in my UIViewController a WKWebViewDelegate, because the website behind this WKWebView needs permission to camera and have to open inside app, because of Apple Design Guidelines.
In my test environment everything is working. I use crashyltics to analyse my apps in live environment. 10-15% of my users (100% = 130 daily users) will get the following problem.
Crashed: com.apple.main-thread
0 CoreFoundation 0x182691968 CFRunLoopAddTimer + 88
1 JavaScriptCore 0x186f6cf98 WTF::RunLoop::TimerBase::start(double, bool) + 188
2 **WebKit** 0x18bb8362c IPC::ConnectionTerminationWatchdog::ConnectionTerminationWatchdog(WTF::OSObjectPtr<NSObject<OS_xpc_object>*>&, double) + 164
3 **WebKit** 0x18bb826d0 IPC::ConnectionTerminationWatchdog::createConnectionTerminationWatchdog(WTF::OSObjectPtr<NSObject<OS_xpc_object>*>&, double) + 48
4 WebKit 0x18bb7c488 WebKit::ChildProcessProxy::shutDownProcess() + 76
5 WebKit 0x18bd35cd0 WebKit::WebProcessProxy::shutDown() + 36
6 WebKit 0x18bd36244 WebKit::WebProcessProxy::removeWebPage(unsigned long long) + 432
7 WebKit 0x18bcd0934 WebKit::WebPageProxy::close() + 536
8 WebKit 0x18bdc3200 -[WKWebView dealloc] + 112
9 libobjc.A.dylib 0x1811f5fe0 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 704
10 UIKit 0x188658668 -[UIView dealloc] + 1644
11 libobjc.A.dylib 0x1811f5fe0 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 704
12 UIKit 0x188658668 -[UIView dealloc] + 1644
....
Another error is
Crashed: com.apple.main-thread
0 libdispatch.dylib 0x190daaf20 _dispatch_barrier_sync_f_slow + 596
1 WebKit 0x19b37701c __64-[WKProcessAssertionBackgroundTaskManager _updateBackgroundTask]_block_invoke + 240
2 WebKit 0x19b37701c __64-[WKProcessAssertionBackgroundTaskManager _updateBackgroundTask]_block_invoke + 240
So I read a lot about EXC_BAD_ACCESS and I understand that a reference point to an object that is nil.
HOW MY WKWebView Looks Like
This is my structure in my storyboard:
I need to use a ContainerView, because my code just work with the line self.view = self.webView
Tried to took just a view but then the WKWebView doesn't initialize.
//WKWebView in Container
var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
webView = WKWebView()
self.webView.navigationDelegate = self
self.view = self.webView
dispatch_async(dispatch_get_main_queue()) {
if self.url.characters.count > 0 {
if let url = NSURL(string: self.url) {
self.webView.loadRequest(NSURLRequest(URL: url))
self.webView.allowsBackForwardNavigationGestures = true
}
}
}
}
Last but not least I detect that when I call the WKWebView (Or the ViewController with the ContainerView that include the WKWebView) with
viewController.presentViewController(vc, animated: true, completion: nil)
and dismiss with
super.dismissViewControllerAnimated(flag, completion: completion)
the memory won't deallocate. So I could (when I call the WKWebView over 100 times) get a memory leak. In the live environment this scenario is really improbable.
However.. the problem is that I can't reproduce this error that my users get. So the question to you before I will send a next version to App Store: Do you see a no go in my code? Something that could threw this errors?
I changed parts of my code to that:
// dispatch_async(dispatch_get_main_queue()) { [weak self] () -> Void in
var webView:WKWebView?
Upvotes: 1
Views: 1709
Reputation: 7524
It was very confusing. My procedure was: User click on Button to WKWebview. I ask for the camera permission. User gave or gave not. User go back. The App shutdown.
When I don't ask for the camera permission then there weren't no interrupts anymore. More I can't find out.
Upvotes: 1