To run the example project, clone the repo, and run pod install
from the Example directory first.
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];
iOS 7.0
MGXWebBridge is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'MGXWebBridge'
MGXWebBridge is available under the MIT license. See the LICENSE file for more info.