项目介绍:
CHWebView
CHWebView is a lightweigh object-c implemented basecontroller for webview.It’s convenient to use webview between WKWebView with UIWebView,both support progressview when you load web.
InstallYou can download zip and drag CHWebView File in your project,also you can install with pod.
pod ‘CHWebView’
Features
- Every controller base on CHWebViewContoller will display progreesview when you loading or use CHWebViewContoller init .
- You can load local resource file in your project more than remote url.
- It will be quick to call js function also convenience when js calling native code.
- Support WKWebView and UIWebView.
Requirements
- iOS 8.0+,
- Xcode 7.3 or above
- JavaScriptCore
- WebKit
Init WbeView[Objective-C] 查看源文件 复制代码
- (instancetype)initWithURL:(NSString *)url; - (instancetype)initWithFile:(NSString *)url; - (instancetype)initWithURL:(NSString *)url withOutNavtionBar:(BOOL)hidden; - (instancetype)initWithFile:(NSString *)url withOutNavtionBar:(BOOL)hidden;
JS Call Object-CObject-C Code[Objective-C] 查看源文件 复制代码
- (NSArray<NSString *> *)registerJavascriptName{ return @[@"native",@"show"]; } - (void)native:(NSDictionary *)dic{ } - (void)show:(id)body{ }
JavaScript Code for WKWebKit[Objective-C] 查看源文件 复制代码
function nativeFounction() { var message = { 'message' : 'Hello, JS!', 'numbers' : [ 1, 2, 3 ] }; window.webkit.messageHandlers.native.postMessage(message); } function showUIFuction(){ window.webkit.messageHandlers.show.postMessage(''); }
JavaScript Code for UIWebView[Objective-C] 查看源文件 复制代码
function nativeFounction() { var message = { 'message' : 'Hello, JS!', 'numbers' : [ 1, 2, 3 ] }; native(message); } function showUIFuction(){ show('call OC function Show') }
Object-C Call JavaScript[Objective-C] 查看源文件 复制代码
- (void)invokeJavaScript:(NSString *)function; - (void)invokeJavaScript:(NSString *)function completionHandler:(void (^)( id, NSError * error))completionHandler;
DEMO 直接下载: