CHWebView 中文使用说明文档
CHWebView is a lightweigh object-c implemented for webview.It's WKWebView and UIWebView adapter. Support progress view when web is loading and html can convenient to call object-c method.
- You can use UIWebView or WKWebView as usual.
- You can load local resource file in your project more than remote url.
- JavaScript call native method just coding in a line .
- Support CHWebViewController to load web.
You can download zip and drag CHWebView File in your project,also you can install with pod.
pod 'CHWebView'
- iOS 8.0+,
- Xcode 7.3 or above
- JavaScriptCore
- WebKit
CHWebView *webView = [[CHWebView alloc]initWithFrame:rect];
[webView loadRequest:self.request];
webView.delegate = self;
[self.view addSubview:webView];
- ( instancetype)initWithUIWebView;
- ( instancetype)initWithUIWebView:(CGRect)frame;
- (instancetype)initWithURL:(NSString *)url;
- (instancetype)initWithFile:(NSString *)url;
- (NSArray<NSString *> *)registerJavascriptName{
return @[@"fetchMessage",@"show"];
}
- (NSObject *)registerJavaScriptHandler{
return self;
}
- (void)fetchMessage:(NSDictionary *)dic{
}
- (void)show:(NSDictionary *)dic{
}
Html can found window.NativeBridge object . window.NativeBridge({f},{j}) @parameter f is native method name maybe it's named show or something else,you can defind it. @parameter j is parameter used by method.
function nativeFounction() {
var obj = { 'message' : 'Hello, JS!', 'numbers' : [ 1, 2, 3 ] };
window.NativeBridge('fetchMessage',obj)
}
function showUIFuction(){
window.NativeBridge('show')
}
- (void)invokeJavaScript:(NSString *)function;
- (void)invokeJavaScript:(NSString *)function completionHandler:(void (^)( id, NSError * error))completionHandler;