[英]Unable to call native all iOS functions from UIWebView using JavaScriptCore and JSContext
Let me explain my question it is bugging me from long time. 让我解释一下我的问题,这困扰着我很长一段时间。 Any help will be appreciated.
任何帮助将不胜感激。 Please help.
请帮忙。
I am working on hybrid kind of app in iOS. 我正在开发iOS中的混合型应用程序。 I am using
UIWebView
for loading webpages from http://myserver.com (its example its not actual URL) I have hosted multiple webpages on this server. 我正在使用
UIWebView
从http://myserver.com加载网页(其示例不是实际的URL),我在此服务器上托管了多个网页。
I am using "JSContext" to communicate between javascript (webpages loaded from my server) in UIWebView
and native iOS functions. 我正在使用“ JSContext”在
UIWebView
javascript (从我的服务器加载的网页)和本机iOS函数之间进行通信。
I have followed procedure given at UIWebView JavaScript losing reference to iOS JSContext namespace (object) the context was getting lost but I have added workaround provided in solution of this question. 我已遵循UIWebView JavaScript上给出的过程, 失去了对上下文丢失的iOS JSContext名称空间(对象)的引用,但是我添加了此问题的解决方案中提供的解决方法。 Event then for some frame load inside
UIWebView
my iOS context is getting vanished. 事件然后为
UIWebView
内的某些框架负载而消失,我的iOS上下文消失了。 After following following steps context gets vanished. 在执行以下步骤后,上下文消失了。
UIWebView
. UIWebView
myserver加载page1 。 Almost all works well all functions OS native iOS are called from javascript . UIWebView
javascript context gets vanished. UIWebView
javascript上下文中将消失。 There is one more magical thing. 还有一件神奇的事情。 if I have directly load page2 in
UIWebView
instead of indirect loading ( page1 -> page2 ). 如果我已经在
UIWebView
直接加载page2而不是间接加载( page1- > page2 )。 All works well all native methods are called from UIwebView
as expected. 一切正常,可以从
UIwebView
调用所有本机方法。 Please help. 请帮忙。 If you want more info please ask.
如果您想了解更多信息,请询问。
First of all, stealing and using the UIWebView's JavaScriptContext in this way is likely a path to app rejection. 首先,以这种方式窃取和使用UIWebView的JavaScriptContext可能是拒绝应用程序的途径。
But if this is just a science project... 但是如果这只是一个科学项目...
You might try another technique for obtaining the JavaScriptContext. 您可以尝试另一种获取JavaScriptContext的技术。 I present a solution in this GitHub project:
我在这个GitHub项目中提出了一个解决方案:
https://github.com/TomSwift/UIWebView-TS_JavaScriptContext https://github.com/TomSwift/UIWebView-TS_JavaScriptContext
Basically I'm using some knowledge of how WebKit works to implement a category on NSObject to intercept some non-handeled WebKit delegate methods which are called whenever a new JavaScriptContext is created for a frame. 基本上,我利用一些WebKit工作原理的知识来实现NSObject上的类别,以拦截一些未处理的WebKit委托方法,每当为框架创建新的JavaScriptContext时,这些方法就会被调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.