//
//  MineWebTableViewCell+initView.swift
//  MobilePortal
//
//  Created by xiejiangbo on 2019/12/18.
//  Copyright © 2019 yin chen. All rights reserved.
//

import UIKit

extension MineWebTableViewCell {

    @available(iOS 8.0, *)
    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        
    }
    
    func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
        print(message.name)
        if message.name == "AppLogout" {
            
        }
    }
    
    func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
        print(webView.url?.absoluteString ?? String())
        print("main frame的导航开始请求时")
    }
    func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {
        print("接收到服务器跳转请求之后调用")
    }
    func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
        print("web内容开始到达时")
        
    }
    
    func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
//        let alertController = UIAlertController.init(title: "提示", message: message, preferredStyle: .alert)
//        alertController.addAction(UIAlertAction.init(title: "确认", style: .default, handler: { (action) in
//            completionHandler()
//        }))
//        self.present(alertController, animated: true, completion: nil)
    }
    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
        print("MineWebTableViewCell allow==",navigationAction.request.url as Any)
        //navigationAction.navigationType
        if navigationAction.targetFrame == nil {
            webView.load(navigationAction.request)
        }
        
        decisionHandler(WKNavigationActionPolicy.allow)
    }

}
