[[using-phonegap-build-with-vaadin-touchkit]]
Using PhoneGap Build with Vaadin TouchKit
-----------------------------------------
At first, using https://build.phonegap.com/[PhoneGap Build] to point to
your Vaadin TouchKit apps seems like a breeze. Just create a simple
`config.xml` and an `index.html` that redirects to your web site, and you
have an app! Unfortunately, simply doing this is not robust. Mobile
devices lose connectivity, and when they do your app not only stops
working, it may appear to freeze up and have to be killed and restarted
to get working again.
With the release of TouchKit v3.0.2 though, there is a solution! This
article summarizes this solution, which was worked out over months of
trial and error on http://dev.vaadin.com/ticket/13250[Vaadin ticket
13250].
'''''
First, server side you need TouchKit v3.0.2. (The needed enhancements
and fixes should roll into _v4.0_ at some point, but as of _beta1_ it isn't
there.) You also need to ensure that your VAADIN directory resources are
being served up by a servlet extending `TouchKitServlet`. If you have a
main application extending `VaadinServlet`, this needs to be changed to
`TouchKitServlet`.
'''''
When your PhoneGap app runs, it loads your provided `index.html` file into
an embedded WebKit browser. Only this file has access to the PhoneGap
Javascript library, so it handles things like offline-mode detection,
and passes this via messages to the iframe containing your
server-provided application.
[source,html]
....
My Application Name
Downloading application files,
Please be patient...
Failed to contact the server.
Please ensure you have a stable Internet connection, and then
touch here to retry.
....
Change the `` and URL in the iframe at the end to match your app.
This also expects a file named `spinner.png` along side `index.html`, which
will be displayed and spin while loading application files from the
server.
This Javascript handles detecting when the app goes offline and back
online (and passes that to TouchKit), provides user feedback during a
long initial load, and provides a friendly retry mechanism if the app is
initially run without network access. It also hides the initial
splashscreen.
'''''
PhoneGap Build requires a config.xml file to tell it how to behave.
Below is a working example that works to create Android 4.0+ and iOS 6 &
7 apps.
[source,xml]
....
My App Name
Example Corp, LLC
Copyright 2014, Example Corp, LLC
....
The listed plugins are all required to make the splash screen and
offline-mode work properly. The slew of icons and splash screen .png
file are required by the app stores, so be sure to include all of them
in the source .zip that you upload to PhoneGap Build. Placing these
files in a subdirectory allows you to also put an empty file named
".pgbomit" in that folder, which ensures that *extra* copies of each of
these file are not included in the file app package produced by PhoneGap
Build.
'''''
Special thanks to "manolo" from Vaadin for working with me for over a
month to make all of this work by creating enhancements to TouchKit and
the index.html file that the above one is based on.