我在这里很大程度上使用了这个进程,以允许javascript从我的iPad应用程序中调用objective c:
http://www.stevesaxon.me/posts/2011/window-external-notify-in-ios-uiwebview/
我注入到页面中的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中,在对象C中调用的唯一方法是最后一个方法Set_C(true);
谢谢。
发布于 2012-11-14 07:05:58
所以我使用了这个博客来让事情变得有效:http://blog.techno-barje.fr/post/2010/10/06/UIWebView-secrets-part3-How-to-properly-call-ObjectiveC-from-Javascript/
https://stackoverflow.com/questions/13254751
复制相似问题