Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
liyuunxiangGit authored Dec 25, 2017
1 parent 63c56f3 commit 35d3e97
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,33 @@ WKNavigationDelegate,WKUIDelegate
_webViewBridge = [WKWebViewJavascriptBridge bridgeForWebView:self.webView];
[_webViewBridge setWebViewDelegate:self.webView];
```
* 3、最后注册js交互的方法,如demo所示:
```
[self registerNativeFunctions];
```
   * registerNativeFunctions方法的实现
 ```
#pragma mark - private method
- (void)registerNativeFunctions
{

[self registTestOneFunction];
}
-(void)registTestOneFunction
{

[_webViewBridge registerHandler:@"testOCFunction" handler:^(id data, WVJBResponseCallback responseCallback) {

// data 的类型与 JS中传的参数有关
NSDictionary *tempDic = [self JSONStringToDictionaryWithData:data];;
// 在这里执行分享的操作
NSString *title = [tempDic objectForKey:@"title"];
NSString *content = [tempDic objectForKey:@"content"];
NSString *url = [tempDic objectForKey:@"url"];

// 将分享的结果返回到JS中
NSString *result = [NSString stringWithFormat:@"js调用native成功成功:\ntitle=%@\n,content=%@\n,url=%@",title,content,url];
responseCallback(result);
}];
}
```

0 comments on commit 35d3e97

Please sign in to comment.