LTJSBridge 1.0

LTJSBridge 1.0

FtkeyJoey维护。



  • 作者:
  • Futao

LTJSBridge

CI Status Version License Platform

示例

要运行示例项目,请克隆仓库,然后从示例目录运行pod install

JS Code:
JSInterface.test(function(result) { clientinfo.innerHTML = "result: " +result; })
JSInterface.test1("str1","str2",function(result) { clientinfo.innerHTML = "result: " ;})
JSInterface.test2("str1","str2","str3","str4");

OC Code:

@interface JSInterface:NSObject <JSBridgeInterface>
@end
@implementation JSInterface

- (nullable NSDictionary<NSString*,NSString*>*)bridgeJSInterfaceMethodMaps {
    return @{
             @"test":NSStringFromSelector(@selector(test:)),
             @"test1":NSStringFromSelector(@selector(test1:::)),
             @"test2":NSStringFromSelector(@selector(test2:string2:string3:string4:))
             };
}
- (nonnull NSString *)bridgeJSInterfaceName {
   return @"JSInterface";
}
- (void)test:(JSBridgeCallBack)callback {
    callback(@"OC Callback [test]");
}
- (void)test1:(NSString*)string1 :(NSString*)string2 :(JSBridgeCallBack)callback {
    NSLog(@"%@,%@",string1,string2);
    callback(@"OC Callback  [test1]");
}
- (void)test2:(NSString*)string1 string2:(NSString*)string2 string3:(NSString*)string3 string4:(NSString*)string4{
    NSLog(@"%@,%@,%@,%@",string1,string2,string3,string4);
    
}
@end

要求

安装

LTJSBridge可通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中

pod 'LTJSBridge'
#import <LTJSBridge/JSBridge.h>

@property(nonatomic, strong) WKWebView *webView;
@property(nonatomic, strong) JSBridge *bridge;

self.bridge =  [JSBridge bridgeByWebView:self.webView];
[self.bridge addJavascriptInterface:[JSInterface new]];

作者

Futao,[email protected]

许可协议

LTJSBridge 授权协议为 MIT。有关更多信息,请参阅 LICENSE 文件。

##感谢 FMWebViewJavascriptBridge