iOS - UIWebViewDelegate intercept javascript calls

前提是你 提交于 2019-12-19 04:58:56

问题


I'm using pretty much the this process oulined here to allow javascript to call objective c from my iPad app:

http://www.stevesaxon.me/posts/2011/window-external-notify-in-ios-uiwebview/

My javascript code that I'm injecting into the page is:

<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>;

And the javascript in the html code that calls the above method for initialization is:

<html>
<body>
...
<script type="text/javascript">

Get_Version();

Set_A(true);
Set_B(false);
Set_C(true);

<script>
</body>
</html>

In the above html the only method that gets called in Objective C is the last method Set_C(true);

Thanks.


回答1:


So I used this blog entry to make things work: http://blog.techno-barje.fr/post/2010/10/06/UIWebView-secrets-part3-How-to-properly-call-ObjectiveC-from-Javascript/



来源:https://stackoverflow.com/questions/13254751/ios-uiwebviewdelegate-intercept-javascript-calls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!