Next, we will study the implementation of phonegap on other platforms. Let's take a look at Windows Phone (WP) today ).
It is relatively simple to connect JS and OS on WP, because the built-in webbrowser provides a better interaction mechanism with JS, including JS debugging and callback Js. Next let's take a look at the architecture diagram, similar to Android:
Next we will focus on the interconnection between JS and wp OS.
1) JS end calls WP end
WP provides webbrowser. scriptpolicy event, which allows js to call window. External. nal y and tune it to the scriptpolicy method in the webbrowser loaded in mainpage. For details, see the following document:
Http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.scriptnotify%28v=vs.95%29.aspx
Phonegap uses pgview to package webbrowser:
[Html]View
Plaincopy
- <Grid x: Name = "LayoutRoot" Background = "Transparent">
- <Phone: WebBrowser x: Name = "GapBrowser"
- HorizontalAlignment = "Stretch"
- VerticalAlignment = "Stretch"
- IsScriptEnabled = "True"
- Foreground = "White"
- Navigated = "GapBrowser_Navigated"
- Loaded = "GapBrowser_Loaded"
- Unloaded = "GapBrowser_Unloaded"
- Scriptpolicy = "gapbrowser_scriptpolicy"
- LoadCompleted = "GapBrowser_LoadCompleted"
- Navigating = "gapbrowser_navigating"
- Navigationfailed = "gapbrowser_navigationfailed"
- Isgeolocationenabled = "true"/>
- </GRID>
As a result, gapbrowser_scriptnotify becomes the JS interface of wp OS, and the corresponding command is dynamically reflected by parameters in gapbrowser_scriptnotify to respond to various requirements.
2) JS return results are reversed on the WP side.
WP provides webbrowser. invokescript, which can call methods in JS loaded in webbrowser from the OS. With this feature, the implementation of returned call results is greatly simplified, it is not as troublesome as Ajax or jsonp on Android. In this way, you do not need to differentiate between synchronous and asynchronous calls. You just need to use Asynchronous calls.
Next let's take a look at the sequence diagram:
It is also worth mentioning that WP does not use a plug-in like android. xml is used to configure the OS logic implementation. Instead, the command class is reflected directly by the passed package name + class name. If the command is provided by the phonegap system, the class name is used for ing, if it is a self-developed command, you need to use the "package name. class Name To map.
Over the past two days, I have seen the implementation of phonegap on android and wp. I feel that it is working hard to help others suffer. In order to provide users with consistent JS APIs, this makes it necessary to make Adapter based on the characteristics of various platforms for JS compatibility. Therefore, from the perspective of big architecture, phonegap does not have much innovation, its core value is to diligently handle the differences in some core API calls on various platforms.