WebView & WKWebView & UIWebView
WebView
WKWebView
https://developer.apple.com/documentation/webkit/wkwebview
UIWebView
https://developer.apple.com/documentation/uikit/uiwebview
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 發布文章使用:只允許注冊用戶才可以訪問!
