objective-c - iOS 开发中 WKWebView 的使用问题拦截跳转
问题描述
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { 请问这里的 webView.URL 和 navigationAction.request.URL 有什么区别? }- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {请问这里的 webView.URL 和 navigationAction.request.URL 有什么区别?}
问题:1.上面代码块里面的问题 webView.URL 和 navigationAction.request.URL 有什么区别?2.当我第一次加载一个网页的时候,上面的代理方法为什么会被调用多次?3.如果我想拦截网页的跳转链接,希望通过 push 打开一个页面重新展示一个 webview,最好是在哪个代理方法里拦截? 遇到重定向问题怎么破?
问题解答
回答1:调多次 是不是因为url有重定向
回答2:你可以打印出来看看他们的值,看看跳转网页的时候是在哪里打印的。文档里有关于这两个代理的说明。
/*! @abstract Decides whether to allow or cancel a navigation. @param webView The web view invoking the delegate method. @param navigationAction Descriptive information about the action triggering the navigation request. @param decisionHandler The decision handler to call to allow or cancel the navigation. The argument is one of the constants of the enumerated type WKNavigationActionPolicy. @discussion If you do not implement this method, the web view will load the request or, if appropriate, forward it to another application. */- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler;/*! @abstract Decides whether to allow or cancel a navigation after its response is known. @param webView The web view invoking the delegate method. @param navigationResponse Descriptive information about the navigation response. @param decisionHandler The decision handler to call to allow or cancel the navigation. The argument is one of the constants of the enumerated type WKNavigationResponsePolicy. @discussion If you do not implement this method, the web view will allow the response, if the web view can show it. */- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler;
相关文章:
1. dockerfile - 我用docker build的时候出现下边问题 麻烦帮我看一下2. java编程思想第4版中文版的几处谬误?3. java - C语言的一道算法题-兄弟郊游问题 求解?4. Mongodb web连接28017后,提示登录的用户名密码在 db那里预设置5. mongodb的java开发中使用两个字段相等查询条件应该怎么写?6. 请问怎么改变超链接字体的颜色?7. java - 做数据库向手机端的推送要系统地学习哪些知识?求大神指点,谢谢!8. 需要一个Java映射/表,其中多个键指向一个值。价值通常会改变9. html - 开发android的调取我web页面 他之前用的是收费的浏览器包 显示是全的换了免费的浏览器包后 显示就不全 是什么原因啊10. Android 不规则裁剪,多边形任意拖动裁剪?
![dockerfile - 我用docker build的时候出现下边问题 麻烦帮我看一下](http://www.haobala.com/attached/image/news/202311/1028095cc6.png)