简体   繁体   English

是否会使用UIWebview中的JSContext来重新调整我的应用程序?

[英]Will using the JSContext from a UIWebview get my app rejcted?

We have a requirement in our app wherein we have to communicate across the web/native boundary - between JavaScript running in a UIWebView and ObjectiveC in the app. 我们的应用程序中有一个要求,我们必须跨Web /本地边界进行通信 - 在UIWebView运行的JavaScript和应用程序中的ObjectiveC之间。

The web component communicates internally via pagebus(a subscription and publishing mechanism) and the requirement is that the native component should also be capable enough to subscribe for those events and listen to them. Web组件通过pagebus(订阅和发布机制)进行内部通信,并且要求本机组件也应该足够能够订阅这些事件并监听它们。

We all know that the only official way to call into a UIWebView from ObjectiveC is via stringByEvaluatingJavaScriptFromString . 我们都知道从ObjectiveC调用UIWebView的唯一官方方法是通过stringByEvaluatingJavaScriptFromString And the typical way to call out from JavaScript is some manner of setting window.location to trigger a shouldStartLoadWithRequest: callback on the UIWebView delegate. 从JavaScript调用的典型方法是设置window.location以触发UIWebView委托上的shouldStartLoadWithRequest: callback。 But this will be not useful to handle page bus events. 但这对处理页面总线事件没有用。

Apple gives us a public JavaScriptCore framework (part of WebKit) in iOS7, and JavaScriptCore provides simple mechanisms to proxy objects and methods between ObjectiveC and the JavaScript “context”. Apple在iOS7中为我们提供了一个公共JavaScriptCore框架(WebKit的一部分),而JavaScriptCore提供了简单的机制来代理ObjectiveC和JavaScript“上下文”之间的对象和方法。

Unfortunately, to make use of this framework in achieving our objective, we need the JSContext object of the webview, but there is no mechanism to achieve it. 不幸的是,为了利用这个框架来实现我们的目标,我们需要webview的JSContext对象,但是没有实现它的机制。 There is a stack overflow link where we found there are two approaches to achieve this (both undocumented). 有一个堆栈溢出链接,我们发现有两种方法可以实现这一点(两者都没有记录)。

Approach 1: Get the JSContext via KVC 方法1:通过KVC获取JSContext

JSContext *ctx = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];

Approach 2: Get the JSContext via WebKit's -didCreateJavaScriptContext delegate callback. 方法2:通过WebKit的-didCreateJavaScriptContext委托回调获取JSContext。

Please find the reference link below Why use JavaScriptCore in iOS7 if it can't access a UIWebView's runtime? 请在下面找到参考链接为什么在iOS7中使用JavaScriptCore,如果它无法访问UIWebView的运行时? The question is can we use either of these methods in our app, so that our app won't get rejected in App Store Or is there any other mechanism to achieve our objective of listening to pagebus events? 问题是我们可以在我们的应用程序中使用这些方法中的任何一种,以便我们的应用程序不会在App Store中被拒绝或者是否有任何其他机制来实现我们监听pagebus事件的目标?

I don't think apple will rejected your app. 我不认为苹果会拒绝你的应用程序。 I use kvc to get jscontext from uiwebview in my app and it pass the app review. 我在我的应用程序中使用kvc从uiwebview获取jscontext并通过了应用程序审核。

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

相关问题 如何在ios5中获取UIwebView的JSContext? - How to get UIwebView's JSContext in ios5? 无法使用JavaScriptCore和JSContext从UIWebView调用本机所有iOS功能 - Unable to call native all iOS functions from UIWebView using JavaScriptCore and JSContext 从JSContext中获取JS Promise / async函数的价值 - Get value from JS Promise/async function from within a JSContext 从UIWebView W / Swift将多个Div元素的属性获取到我的iOS应用中 - Get Attribute From Multiple Div Elements into my iOS app from UIWebView W/Swift 使用JSContext从Swift中的JavaScript捕获print语句 - Catching print statement from JavaScript in Swift using JSContext 使用JavascriptCore和JSContext从javascript调用本机Swift代码 - Calling native Swift code from javascript using JavascriptCore and JSContext 如何将 UIWebView 中的 JSContext 重新用于 WKWebview 的 WKScriptMessage - How do I repurpose JSContext in UIWebView to WKScriptMessage for WKWebview UIWebView JavaScript失去对iOS JSContext名称空间(对象)的引用 - UIWebView JavaScript losing reference to iOS JSContext namespace (object) 为什么在使用 Arrow function 时在 Swift 中无法获得 function 引用 - Why I can't get function reference by JSContext in Swift when using Arrow function 如何在Fennec中获取当前选项卡的jscontext? - How to get jscontext of current tab in fennec?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM