欢迎光临
我们一直在努力

WebView加载进度条和JS与OC交互

建站超值云服务器,限时71元/月

WebView加载进度条和JS与OC交互

项目介绍:

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 直接下载:

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » WebView加载进度条和JS与OC交互
分享到: 更多 (0)