iOS – UIWebViewDelegate拦截javascript调用

我正在使用这个程序,以允许javascript从我的iPad应用程序调用目标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中,在Objective C中调用的唯一方法是最后一个方法Set_C(true);

谢谢。

所以我使用这个博客条目来使事情工作: http : //blog.techno-barje.fr/post/2010/10/06/UIWebView-secrets-part3-How-to-properly-call-ObjectiveC-from-Javascript /