https://github.com/chausson/CHWebView
  
  
    统一简化UIWebView和WKWebView的API使用,在此基础上实现进度条和简单JS交互事件 
    https://github.com/chausson/CHWebView
  
        Last synced: 4 months ago 
        JSON representation
    
统一简化UIWebView和WKWebView的API使用,在此基础上实现进度条和简单JS交互事件
- Host: GitHub
 - URL: https://github.com/chausson/CHWebView
 - Owner: chausson
 - License: mit
 - Created: 2016-07-22T08:45:34.000Z (over 9 years ago)
 - Default Branch: master
 - Last Pushed: 2018-01-08T12:09:23.000Z (almost 8 years ago)
 - Last Synced: 2025-06-12T03:16:37.445Z (5 months ago)
 - Language: Objective-C
 - Homepage:
 - Size: 1.65 MB
 - Stars: 136
 - Watchers: 8
 - Forks: 35
 - Open Issues: 1
 - 
            Metadata Files:
            
- Readme: README.md
 - License: LICENSE
 
 
Awesome Lists containing this project
- awesome - CHWebView - 简化UIWebView和WKWebView的API使用,在此基础上实现进度条和简单JS交互事件。【 [Priview 1](https://github.com/chausson/CHWebView/raw/master/Resource/WebView.gif) | [Priview 2](https://github.com/chausson/CHWebView/raw/master/Resource/CHWebView.png) 】 (OOM-Leaks-Crash / WebView-ProgressBar)
 
README
          # CHWebView [中文使用说明文档](https://github.com/chausson/CHWebView/tree/master/ChineseMd)
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.
[](http://www.cocoapods.org/?q=CHWebView)



# Features
* 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.
# Install
You can download zip and drag CHWebView File in your project,also you can install with pod.
``` bash
pod 'CHWebView'
```
# Requirements
* iOS 8.0+, 
* Xcode 7.3 or above
* JavaScriptCore
* WebKit
# Init CHWbeView
``` obj-c
    CHWebView *webView = [[CHWebView alloc]initWithFrame:rect];
    [webView loadRequest:self.request];
    webView.delegate = self;
    [self.view addSubview:webView];
```
# If you want change UIWebView
``` obj-c
  - ( instancetype)initWithUIWebView; 
  - ( instancetype)initWithUIWebView:(CGRect)frame;
```
# Also you can use CHWebViewConroller
``` obj-c
- (instancetype)initWithURL:(NSString *)url;
- (instancetype)initWithFile:(NSString *)url;
```
# JS Call Object-C OC CODE
``` obj-c
- (NSArray *)registerJavascriptName{
    return @[@"fetchMessage",@"show"];
}
- (NSObject *)registerJavaScriptHandler{
    return self;
}
- (void)fetchMessage:(NSDictionary *)dic{
}
- (void)show:(NSDictionary *)dic{
}
```
# JavaScript Code 
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.
``` javascript
 function nativeFounction() {
       var obj = { 'message' : 'Hello, JS!', 'numbers' : [ 1, 2, 3 ] };
       window.NativeBridge('fetchMessage',obj)
   }
    function showUIFuction(){
       window.NativeBridge('show')
    }
```
# Object-C Call JavaScript
``` obj-c
- (void)invokeJavaScript:(NSString *)function;
- (void)invokeJavaScript:(NSString *)function completionHandler:(void (^)( id, NSError * error))completionHandler;
```
# CHWebView Design