Communication from the JavaScriptCore WebView

JavascriptCore

JavascriptCore been built as WebKit JS engine, after iOS7, Apple the original C / C ++ code OC a package, system-level framework for become developers. As an engine is concerned, JavascriptCore lexical, syntax analysis, as well as multi-level JIT compiler technology is worth digging and learn directions, due to space restrictions for the time being not in-depth discussion.

JavascriptCore.framework

Although JavascriptCore.framework only exposes fewer header files and system functions, but offers from App WebView in the execution environment and the ability of JavaScript.

  • JSVirtualMachine: providing the underlying resource and memory JS execution. Although Java and JavaScript nothing to do, but the same as a virtual machine, JSVM JVM and made a part of something similar, each JSVirtualMachine exclusive thread, an independent space and management, but can contain multiple JSContext.
  • JSContext: provides the context and the interface JS run, it can not be accurately understood as a Window object is created in JavaScript.
  • JSValue: JS provided between OC and encapsulation and data type conversion Type Conversions. In addition to basic data types, note the OC Block convert the JS function, Class Constructor convert the like.
  • JSManagedValue: JavaScript using the GC memory management mechanism, and OC uses reference counting approach to managing memory. So JavascriptCore course, will inevitably encounter the problem of circular references and early release. JSManagedValue solve the problem of memory management in both environments.
  • JSExport: Providing call interface classes, properties, and examples of the method. Internally corresponding properties and methods implemented in ProtoType & Constructor. 

Communicate using JavascriptCore

For superficial understanding JavascriptCore, can be considered using the Block method, the interior is to save the Block to a Web environment global Object, such as Window, using JSExport method is Object in a Web environment prototype created properties, instance methods , create a class constructor method in the object in order to achieve invoke Web.

  • Native - Web: By JavascriptCore, Native JS statement may be performed directly in the Context, and the Web to communicate and interact side.

  • Web - Native: Native laterally for Web communications, JavaScriptCore two ways, Register Block & Export protocol.

3. App scenarios in

  • WebView-based communications, mainly for H5 App injected into the page JavaScript Open Api, such as providing Native camera, audio and video, location, and login and sharing in the App function. 
  • JavascriptCore, then gave birth to the dynamic, vigorous development of a series of cross-platform technology and thermal repair.

https://my.oschina.net/editorial-story/blog/3094539

Guess you like

Origin www.cnblogs.com/feng9exe/p/11739325.html