简体   繁体   English

从混合应用程序从UIwebview访问iOS本机属性/方法

[英]Accessing iOS native properties/methods from UIwebview from a hybrid app

I am not an iOS expert. 我不是iOS专家。 I have a basic question, Is it possible to access/call any Objective C methods/properties from UI webview? 我有一个基本问题,是否可以从UI Webview访问/调用任何Objective C方法/属性? In other words what would happen if i keep some objective C code in a HTML page and load it in UIwebview of an iOS hybrid app? 换句话说,如果我在HTML页面中保留一些目标C代码并将其加载到iOS混合应用程序的UIwebview中,将会发生什么? Will the code execute? 代码会执行吗?

No - the code will not execute. 否-代码将不会执行。 What you're describing is an "injection" and, if it were possible, could wreak havoc in an app. 您所描述的是“注入”,并且如果可能的话,可能会对应用造成严重破坏。

Something I've done in the past is create an app with a UIWebView container (somewhat like you're describing) then pass back a response that my code can programmatically look for and handle. 我过去做过的事情是使用UIWebView容器创建一个应用程序(有点像您描述的那样),然后传回响应,我的代码可以以编程方式查找和处理。 This is of course possible by the fact I wrote both the app and the web back-end. 当然,这是因为我同时编写了应用程序和Web后端。

I'm sure there are other ways to do this but it has worked for me. 我敢肯定还有其他方法可以做到这一点,但是它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM