Giter VIP home page Giter VIP logo

chwebview's Introduction

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.

CocoaPods Platform info License MIT

image

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.

pod 'CHWebView'

Requirements

  • iOS 8.0+,
  • Xcode 7.3 or above
  • JavaScriptCore
  • WebKit

Init CHWbeView

    CHWebView *webView = [[CHWebView alloc]initWithFrame:rect];
    [webView loadRequest:self.request];
    webView.delegate = self;
    [self.view addSubview:webView];

If you want change UIWebView

  - ( instancetype)initWithUIWebView; 
  - ( instancetype)initWithUIWebView:(CGRect)frame;

Also you can use CHWebViewConroller

- (instancetype)initWithURL:(NSString *)url;

- (instancetype)initWithFile:(NSString *)url;

JS Call Object-C OC CODE

- (NSArray<NSString *> *)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.

 function nativeFounction() {
       var obj = { 'message' : 'Hello, JS!', 'numbers' : [ 1, 2, 3 ] };
       window.NativeBridge('fetchMessage',obj)
   }
    function showUIFuction(){
       window.NativeBridge('show')
    }

Object-C Call JavaScript

- (void)invokeJavaScript:(NSString *)function;

- (void)invokeJavaScript:(NSString *)function completionHandler:(void (^)( id, NSError * error))completionHandler;

CHWebView Design

chwebview's People

Contributors

chausson avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.