- Using WKWebView
- Config customer plugins
- Config Inject common js code
- Integration HybirdFramework, create www bundle folder
- Create controller extend WKWebViewController
- [[viewController alloc] initWithHTML:path]; or [[[viewController alloc] init] initWKWebviewHTML:path]
- in your project plist create
JSBridgeConfig(NSDictionary)
- if you want to inject common scripts you can create
injectScripts(Array)
and then additem(NSDictionary)
includedpath(NSString)
which ignore www/ folder andinjectTime (Boolean)
NO is inject when document load , YES is inject after document loaded.Both required!!! - If you want to add customer plugins you can create
plugins(Array)
and then additem(NSDictionary)
includedExportJsName(String)
which you js code call function name ,ClassName(String)
which you OC code. Both required!!!
-
In JS, When your init the controller, WKWebViewController will inject window.APPBridges Object in webView, so you can call
window.APPBridges.ExportJsName({method:methodName,params:{}},callbackFunction);
callbackFunction is options. if you want to usepromise
you can setwindow.APPBridges.usePromise = true;
-
In Native, you should create a class which need extend
BridgeBase Class
. In this class it have 2 properties and 6 instance methods.2 properties:webView and viewController 6 instance methods: - (void)execJsCallbackFunctionByCallbackId:(NSString *)callback andStatus:(ResponseStatus) callBackType; - (void)execJsCallbackFunctionByCallbackId:(NSString *)callback messageWithReturnDictionary:(NSDictionary *)message andStatus:(ResponseStatus) callBackType; - (void)execJsCallbackFunctionByCallbackId:(NSString *)callback messageWithReturnArray:(NSArray *)message andStatus:(ResponseStatus) callBackType; - (void)execJsCallbackFunctionByCallbackId:(NSString *)callback messageWithReturnNumber:(NSNumber *)message andStatus:(ResponseStatus) callBackType; - (void)execJsCallbackFunctionByCallbackId:(NSString *)callback messageWithReturnString:(NSString *)message andStatus:(ResponseStatus) callBackType; - (void)execJsCallbackFunctionByCallbackId:(NSString *)callback messageWithReturnBoolean:(BOOL)message andStatus:(ResponseStatus) callBackType;
-
After extend BridgeBase Class, you can wirte you instance methods, one limit in instance , only have one param and which need BridgeModel type. BridgeModel included params and callbackId.params is you send by js code used
window.APPBridges.ExportJsName({method:methodName,params:{}});
callbackId just when you call this function, APPBridge create a unique id.
Thinking