我几乎使用了这里概述的这个过程来允许 javascript 从我的 iPad 应用程序调用 Objective C:
http://www.stevesaxon.me/posts/2011/window-external-notify-in-ios-uiwebview/
我要注入(inject)到页面中的 JavaScript 代码是:
<script type="text/javascript">;
window.external =
{
'Set_A': function(s) { document.location = 'qms://Set_A?param=' + s; },
'Get_A': function(s) { document.location = 'qms://Get_A'; },
'Set_B': function(s) { document.location = 'qms://Set_B?param=' + s; },
'Get_B': function(s) { document.location = 'qms://Get_B'; },
'Set_C': function(s) { document.location = 'qms://Set_C?param=' + s; },
'Get_C': function(s) { document.location = 'qms://Get_C'; },
'Get_Version': function(s) { document.location = 'qms://Get_Version'; }
};
</script>;
而调用上述方法进行初始化的html代码中的javascript为:
<html>
<body>
...
<script type="text/javascript">
Get_Version();
Set_A(true);
Set_B(false);
Set_C(true);
<script>
</body>
</html>
在上面的 html 中,Objective C 中唯一调用的方法是最后一个方法 Set_C(true);
谢谢。
最佳答案
因此,我使用此博客条目来使事情正常进行:http://blog.techno-barje.fr/post/2010/10/06/UIWebView-secrets-part3-How-to-properly-call-ObjectiveC-from-Javascript/
关于javascript - iOS - UIWebViewDelegate 拦截 javascript 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13254751/