oc 代码
NSString *jsonString = @"";
if (dic&&dic.count>0) {
jsonString = dictionaryToJson(dic);
}
[self.webView evaluateJavaScript:[NSString stringWithFormat:@"webOnload(%@)",jsonString] completionHandler:^(id _Nullable obj, NSError * _Nullable error) {
}];
///其中webOnload是方法名, jsonString 是传给js的参数
js 代码
function webOnload(e) {
e && e.votedList && e.allVoteInfo && (initUserVote(e.votedList, e.allVoteInfo), setTimeout(function() {
sendWebHeight()
}, 500)),
imgFactory(function() {
loadTimeLine(),
sendWebHeight(),
initGallery(),
askip(),
setTimeout(function() {
LinkApp.initPage(),
TimeLine()
}, 200),
showimg.initshowimg(),
votePK(),
ordinaryVote()
})
}
以上代码即可完成oc 调用js 方法