My View Controller embedded inside a navigation controller holds a WKWebview on which I want to enable the following logic:
If a back item exists in the webview, making a left screen edge gesture should go back one page in the webview (normal behaviour of webview when allowsBackForwardNavigationGestures is set to yes). When there isnt any back item, it should pop one page in the navigation controller (interactivePopGestureRecognizer). I enabled both and I get random results, sometimes I go back one page in the webview and sometimes I go back to my home page in the navigation stack. I tried the following logic:
-(void)webView:(WKWebView *)webView didCommitNavigation:(null_unspecified WKNavigation *)navigation {
if (webView.backForwardList.backItem) {
MYappDelegate.mainNavigationController.interactivePopGestureRecognizer.enabled = NO;
self.webView.allowsBackForwardNavigationGestures = YES;
} else {
MYappDelegate.mainNavigationController.interactivePopGestureRecognizer.enabled = YES;
self.webView.allowsBackForwardNavigationGestures = NO;
}
}
but it crashes when I swipe and I get "WKCompositingView unrecognized selector sent to instance."
Any ideas where I'm going wrong? Im guessing there is a conflict regarding which gesture takes priority but I cant figure out where to add this logic so both the webview and the navigation controller containing its view controller live peacefully.