Skip to content

基于UIWebView的ObjC和JavaScript交互工具,支持返回值

License

Notifications You must be signed in to change notification settings

changjianfeishui/MGXWebBridge

Repository files navigation

MGXWebBridge

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Usage

JS to Objc:

    self.bridge = [[MGXWebBridge alloc]initWithWebView:self.webView];
    [self.bridge registerObjcFuncForJS:@"liveCallHanlder"];
    __weak typeof(self) weakSelf = self;
    self.bridge.JSHander = ^id(NSString * _Nonnull funcName, NSArray * _Nonnull params) {
        NSLog(@"%@===%@",funcName,params);
        if ([funcName isEqualToString:@"liveCallHanlder"]) {
            return [weakSelf liveCallHanlder];
        }
        return nil;
    };

Objc to JS:

    NSDictionary *param = @{
                            @"name":@"lilei",
                            @"age":@"13",
                            @"sex":@"1",
                            @"friends":@[@"han",@"li"]
                            };
    //support param type: NSString , NSArray, NSDictionary
    [self.bridge invokeJSFunc:@"ajaxResult.list" params:param];

Requirements

iOS 7.0

Installation

MGXWebBridge is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'MGXWebBridge'

License

MGXWebBridge is available under the MIT license. See the LICENSE file for more info.

About

基于UIWebView的ObjC和JavaScript交互工具,支持返回值

Resources

License

Stars

Watchers

Forks

Packages

No packages published