xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

WebView & WKWebView & UIWebView

WebView & WKWebView & UIWebView

WebView

WKWebView

https://developer.apple.com/documentation/webkit/wkwebview

UIWebView

https://developer.apple.com/documentation/uikit/uiwebview

https://www.hackingwithswift.com/example-code/wkwebview/whats-the-difference-between-uiwebview-and-wkwebview

https://forums.expo.io/t/received-mail-from-apple-about-the-deprecated-api-uiwebview/27117/15

https://developer.apple.com/documentation/webkit/wkwebview


import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
    
    var webView: WKWebView!
    
    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let myURL = URL(string:"https://www.apple.com")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)
    }
}


//: A UIKit based Playground for presenting user interface


// PlaygroundSupport
import PlaygroundSupport

import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
    
    var webView: WKWebView!
    
    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        view = webView
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let myURL = URL(string: "https://cdn.xgqfrms.xyz")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)
    }
}

PlaygroundPage.current.liveView = ViewController();

/*
  
import UIKit
import PlaygroundSupport

class MyViewController : UIViewController {
    override func loadView() {
        let view = UIView()
        view.backgroundColor = .white

        let label = UILabel()
        label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
        label.text = "Hello World!"
        label.textColor = .black
        
        view.addSubview(label)
        self.view = view
    }
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()

*/


JsBridge

原生开发可以访问平台所有功能,而混合开发中,H5 代码是运行在 WebView 中,
而 WebView 实质上就是一个浏览器内核,其 JavaScript 依然运行在一个权限受限的沙箱中,
所以对于大多数系统能力都没有访问权限,如无法访问文件系统、不能使用蓝牙等。

所以,对于 H5 不能实现的功能,都需要原生去做。
而混合框架一般都会在原生代码中预先实现一些访问系统能力的 API, 然后暴露给 WebView 以供 JavaScript调用;
这样一来,WebView 就成为了 JavaScript与原生 API之间通信的桥梁,主要负责 JavaScript与原生之间传递调用消息;
而消息的传递必须遵守一个标准的协议,它规定了消息的格式与含义;
我们把依赖于 WebView的用于在 JavaScript与原生之间通信并实现了某种消息传输协议的工具称之为 WebView JavaScript Bridge, 简称 JsBridge,它也是混合开发框架的核心。

WebView Scheme / URL Scheme

https://book.flutterchina.club/chapter1/mobile_development_intro.html

refs



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


posted @ 2020-01-20 14:13  xgqfrms  阅读(187)  评论(9编辑  收藏  举报