PhoneGap: It's possible to use only the phoneg

2020-02-29 10:38发布

问题:

It seems that I haven't understood correctly how PhoneGap works. I thought: Take an index.html, include the PhoneGap.js in as type of JavaScript and open the result on iPad/iPhone.

But then, none of the functions like accelerometer, beep(), vibrate() is working. Is it necessary to build an app for that for working correctly?

I have a Webpage and I want only include the functions of PhoneGap so that the iPad can recognize if it was shaken or a draggable HTML Element was touched and thrown at an other place on screen.

Is sencha able to do that and is it the better choice?

Greetz and Thanks!

Markus

回答1:

PhoneGap is a native application wrapper for a variety of different phone platforms. It requires that you use the PhoneGap framework, which is written in native code for each supported platform, for whatever platform you are targeting, and allows you to drop HTML, CSS and JS assets into this framework so that you can build applications for a phone with only those web technologies.

Simply including phonegap.js on a web site that is hosted on a server will not work, because phonegap.js communicates with the (native) PhoneGap framework code. The framework code does the work of accessing the phone's APIs for vibrate, accelerometer, contacts and compass functionality (among others). phonegap.js simply provides a consistent API in JavaScript for accessing this native device functionality.



回答2:

There is no access from Javascript hosted in an ordinary web page to the accelerometer on the iPad as of today -- which is the first piece of functionality that you want to access. If you want to use Sencha (I work for Sencha), you must wrap Sencha code with Phonegap's native shell in order to get access to this functionality. Phonegap takes native Objective C API's and creates new Javascript objects that correspond to these API's. But the result will be a native app, not a web page.

Drag and Drop, the second piece of functionality that you want, is an activity entirely within the browser, and Sencha handles drag and drop just fine.