UIWebView delegate method shouldStartLoadWithRequest: equivalent in WKWebView?

前端 未结 7 938
忘掉有多难
忘掉有多难 2020-12-12 14:37

I have a module inside my iOS 7+ app which is a UIWebView. The html page loads a javascript that creates custom-shaped buttons (using the Raphaeljs library). With UIWebView,

7条回答
  •  情深已故
    2020-12-12 14:58

    I've been looking for a good explanation myself, but haven't found one. I've used the following in my app and everything seems to work (Edit: updated based on ccoroom's comment):

    UIWebViewDelegate     - webView:shouldStartLoadWithRequest:navigationType:
    WKNavigationDelegate  - webView:decidePolicyForNavigationAction:decisionHandler:
    

    Here's the other UIWebViewDelegate methods:

    UIWebViewDelegate     - webViewDidStartLoad:
    WKNavigationDelegate  - webView:didCommitNavigation:
    
    UIWebViewDelegate     - webViewDidFinishLoad:
    WKNavigationDelegate  - webView:didFinishNavigation:
    
    UIWebViewDelegate     - webView:didFailLoadWithError:
    WKNavigationDelegate  - webView:didFailNavigation:withError:
                          - webView:didFailProvisionalNavigation:withError:
    

    I'd love for someone to confirm this for me though.

    Edit: Actually, I've answered the question you had in the title (although I'm no longer confident that webView:didCommitNavigation: is called at the exact same point in the lifecycle), but re-reading your description it looks like what you actually need to know about is how to reimplement a Javascript/Objective-C bridge using WKWebView. So have a look at my other answer.

提交回复
热议问题