objective-c - iOS 開發(fā)中 WKWebView 的使用問題攔截跳轉(zhuǎn)
問題描述
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { 請(qǐng)問這里的 webView.URL 和 navigationAction.request.URL 有什么區(qū)別? }- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {請(qǐng)問這里的 webView.URL 和 navigationAction.request.URL 有什么區(qū)別?}
問題:1.上面代碼塊里面的問題 webView.URL 和 navigationAction.request.URL 有什么區(qū)別?2.當(dāng)我第一次加載一個(gè)網(wǎng)頁的時(shí)候,上面的代理方法為什么會(huì)被調(diào)用多次?3.如果我想攔截網(wǎng)頁的跳轉(zhuǎn)鏈接,希望通過 push 打開一個(gè)頁面重新展示一個(gè) webview,最好是在哪個(gè)代理方法里攔截? 遇到重定向問題怎么破?
問題解答
回答1:調(diào)多次 是不是因?yàn)閡rl有重定向
回答2:你可以打印出來看看他們的值,看看跳轉(zhuǎn)網(wǎng)頁的時(shí)候是在哪里打印的。文檔里有關(guān)于這兩個(gè)代理的說明。
/*! @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;
相關(guān)文章:
1. 數(shù)組按鍵值封裝!2. angular.js - webpack build后的angularjs路由跳轉(zhuǎn)問題3. java - web項(xiàng)目中,用戶登陸信息存儲(chǔ)在session中好 還是cookie中好,取決于什么?4. 老師,怎么不講一次性添加多個(gè)數(shù)據(jù)5. mysql - 查詢字段做了索引為什么不起效,還有查詢一個(gè)月的時(shí)候數(shù)據(jù)都是全部出來的,如果分拆3次的話就沒問題,為什么呢。6. mysql - 大部分?jǐn)?shù)據(jù)沒有行溢出的text字段是否需要拆表7. pdo - mysql 簡單注入疑問8. Mysql取下一條記錄9. python - linux 下用wsgifunc 運(yùn)行web.py該如何修改代碼10. 表格對(duì)其 只涉及到對(duì)其,沒有涉及到大小,長寬還有背景色類的嗎
