-
Notifications
You must be signed in to change notification settings - Fork 142
How do I access Platform APIs from each platform
This is a quick pointer, a more detailed entry is on the way
There is actually a different answer for each platform, and we're working on a more detailed walk through. We also have something in the works to try to automate this for the Cordova polyfills, since that is where the real challenge is:
-
FireFox OS: Accessible from page with JS. Check this resource as to which ones are accessible from a hosted app, https://developer.mozilla.org/en-US/Apps/Reference/Firefox_OS_device_APIs
-
Chrome OS: limited to no device APIs, see this article for details: http://www.thishereweb.com/hosted-web-apps-explained/. In Chrome's defense, they also cover the most Web APIs.
-
Windows 10: Accessible from page with JS. API access can be turned on for any domain, by adding
apiAccess="all"
into yourmjs_access_whitelist
rules. Here is an example file: http://travelcontoso.azurewebsites.net/manifest.json -
iOS / Android: this is a bit trickier, since it's a Cordova Polyfill, you need to add the Cordova files to your website. Three steps:
-
move the content from the www folder (after adding plugin) to your webserver
-
reference the cordova.js file and the cordova_plugins.js file from your page
-
Load appropriate cordova.js content for each platform. This is where it gets tricky if you are supporting both iOS and Android (BTW, we build a windows 10 cordova platform as well, if you want to handle them all together). The cordova.js file, which is required for the plugins to know where to load from (they use the path of this file). I'm playing with three different ways to solve this:
- do some client detection on the server to serve the right version, pretty easy in Node.js
- make the cordova.js file empty and then add the code back in a third js file called
cordova_android.js
andcordova_ios.js
, for each platform appropriately - remove the code from cordova.js and replace with a client detection that then loads the appropriate version.
As you can see, it takes a little bit of work, but once this is done, you can do all your updates from the web server, and never need to deploy again (until you change domain usage :) )