In iOS, Cordova's Cdvviewcontroller inherits Viewcontroller, and each H5 page corresponds to a cdvviewcontroller,
There is a webview, which is a view that is specifically displayed on the H5 page in iOS.
H5 and the original end of the interaction, mainly through the form of plug-ins, the original side write a class inherit Cdvplugin, and then implement the method, JS over the way to encapsulate each interface,
The call is finally made by calling exec in Cordova.js, passing in the service class name, method name, and callback functions and parameters.
Its principle of communication is: there are two ways
1. By inserting an invisible iframe into HTML through the Iframe,cordova.exec function, a special URL is loaded to the UIWebView request.
The URL includes the class name of the plugin plug-in, the method name.
The Uiweibviewdegate shouldstartloadwithrequest is triggered because the URL is requested
This will enter the native, and the native is processed by the request to get the class name and method name
2, through the xhr,cordova.exec through the initiation of a XHR request, this time will be Nsurlprotocol intercept
The native caninitwithrequest will be called to enter the native
Native Invoke JS method, is directly through the stringbyevaluatingjavascriptfromstring directly call JS method
iOS Cordova native and JS communication principle