Phonegap source code analysis (2) -- Windows Phone

Source: Internet
Author: User

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

  1. <Grid x: Name = "LayoutRoot" Background = "Transparent">
  2. <Phone: WebBrowser x: Name = "GapBrowser"
  3. HorizontalAlignment = "Stretch"
  4. VerticalAlignment = "Stretch"
  5. IsScriptEnabled = "True"
  6. Foreground = "White"
  7. Navigated = "GapBrowser_Navigated"
  8. Loaded = "GapBrowser_Loaded"
  9. Unloaded = "GapBrowser_Unloaded"
  10. Scriptpolicy = "gapbrowser_scriptpolicy"
  11. LoadCompleted = "GapBrowser_LoadCompleted"
  12. Navigating = "gapbrowser_navigating"
  13. Navigationfailed = "gapbrowser_navigationfailed"
  14. Isgeolocationenabled = "true"/>
  15. </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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.