You can write hybrid modules in just a few lines of code by using WKWebViewJavascriptBridge without the need to be concerned with the underlying messaging implementation.
Why Only Support WKWebView?
Advantages of WKWebView
It is well known that WKWebView loads web pages faster and more efficiently than UIWebView, and also doesn’t have as much memory overhead for you.
Under the current timeline, most iOS apps only support iOS 9.0+.
UIWebView Cross-Domain Access Vulnerability
The reason for the iOS platform cross-domain access vulnerability is due to UIWebView turning on the WebKitAllowUniversalAccessFromFileURLs and WebKitAllowFileAccessFromFileURLs options.
WKWebView default allowFileAccessFromFileURLs and allowUniversalAccessFromFileURLs option is false.
Features
Swift Support: Swift 3.2 ~ 5 Support.
High Performance: The messaging performance is higher than intercept requests.
High Speed: No need to consider alert box safety timeout.
Lightweight: This framework contains only 3 files.
Non-intrusive: There is no need to make the webview class inherit from other base class.
Usage
1. Instantiate WKWebViewJavascriptBridge with a WKWebView:
What Can WKWebViewJavascriptBridge Do?
You can write hybrid modules in just a few lines of code by using WKWebViewJavascriptBridge without the need to be concerned with the underlying messaging implementation.
Why Only Support WKWebView?
Advantages of WKWebView
It is well known that WKWebView loads web pages faster and more efficiently than UIWebView, and also doesn’t have as much memory overhead for you.
Under the current timeline, most iOS apps only support iOS 9.0+.
UIWebView Cross-Domain Access Vulnerability
The reason for the iOS platform cross-domain access vulnerability is due to UIWebView turning on the WebKitAllowUniversalAccessFromFileURLs and WebKitAllowFileAccessFromFileURLs options.
WKWebView default allowFileAccessFromFileURLs and allowUniversalAccessFromFileURLs option is false.
Features
Usage
1. Instantiate WKWebViewJavascriptBridge with a WKWebView:
2. Register a Handler in Native, and Call a JS Handler:
3. Copy and Paste setupWKWebViewJavascriptBridge into Your JS:
4. Finally, Call setupWKWebViewJavascriptBridge and then Use The Bridge to Register Handlers and Call Native Handlers:
Installation
Cocoapods
pod 'WKWebViewJavascriptBridge', '~> 1.2.0'
to your Podfile.pod install
orpod update
.import WKWebViewJavascriptBridge
.Carthage
github "Lision/WKWebViewJavascriptBridge" ~> 1.2.0
to your Cartfile.carthage update --platform ios
.WKWebViewJavascriptBridge
framework to your project.Manually
Either clone the repo and manually add the Files in WKWebViewJavascriptBridge.
Requirements
This framework requires
iOS 9.0+
andXcode 9.0+
.Contact
License
WKWebViewJavascriptBridge is provided under the MIT license. See LICENSE file for details.