Building Native Mapping Apps with PhoneGap: Advanced Techniques Andy Gup @agup
Agenda Application life-cycle Working with UI frameworks Security Geolocation Offline
Expectations Experience with PhoneGap and/or Cordova Intermediate/Advanced JS, CSS Mobile JS debugging skills Native app debugging skills
Requirements ArcGIS JS API v3.10 – v3.14 PhoneGap/Cordova 5.x Latest gen iPhone and/or Android
Caveats PhoneGap/Cordova not officially supported There may be hidden gotchas Best practices will minimize gotchas
quickstart-map-phonegap github.com/Esri/quickstart-map-phonegap Samples Best practices
PhoneGap Application Lifecycle
Lifecycle Native HTML, CSS, JS PhoneGap Application ArcGIS JS API Map Layers
Lifecycle Part 1 Native PhoneGap Application
Lifecycle Part 2 Native HTML, CSS, JS PhoneGap Application Native WebView <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Map</title> </head> <body> . . . </body> </html>
Lifecycle Part 3 Native HTML, CSS, JS PhoneGap Application ArcGIS JS API
Lifecycle Part 4 Native HTML, CSS, JS PhoneGap Application ArcGIS JS API Map
Lifecycle Part 5 Native HTML, CSS, JS PhoneGap Application ArcGIS JS API Map Layers
UX Frameworks
UX Frameworks + Maps Some considerations: Do view transitions cache pages? Does map get re-created after transition? Map widgets work portrait & landscape? Gracefully handle loss of internet?
Bootstrap-map-js github.com/Esri/bootstrap-map-js Auto-resize map Auto-center map Not PhoneGap tested
Jquery-mobile-map-js github.com/Esri/jquery-mobile-map-js Auto-resize map Auto-center map
View-based Approach Single page, single view Single page, multi-view Multi-page
VIEW 1 VIEW 2
JS library loading Synchronous vs Asynchronous
Synchronous vs async Trade-offs in map load performance Dependencies between libs? Synchronous forces life cycle management Consider concatenating JS libs
Synchronous Time (milliseconds) map.css jquery.css gp.js
Async Time (milliseconds) map.css jquery.css gp.js
Host files locally HTML, CSS, JS, images Significantly faster load times! Security (no interceptions)
ArcGIS Web Optimizer One JS library file! http://jso.arcgis.com/
Security Whitelisting (as of Cordova 4.0) Content Security Policy (CSP) iOS 4.0.0 + Android 4.0.0 +
Security Mitigate XSS attacks Data injection attacks Unauthorized images
config.xml - Navigation Whitelist
config.xml - Intent Whitelist
Content Security Policy (CSP)
Content Security Policy (CSP) Directives
Geolocation with PhoneGap
Geolocation with PhoneGap Same coding pattern. Works online and offline Approximate location Still always requires user opt-in.
Geolocation with PhoneGap Can allow for passive location Does not increase accuracy Does not speed up acquisitions times Outdoors – turn off WiFi! github.com/Esri/html5-geolocation-tool-js
Geolocation (online) Online location Location Service (Google, Microsoft, Apple) WiFi info GPS Cell network info
Geolocation (offline) Offline location determination GPS only!!
Offline JS
Bad pattern!
Good pattern!
Offline JS Intermittent or no internet Ability to reload or restart app offline Lightweight cross-browser functionality Github.com/esri/Offline-editor-js
Offline JS Offline tiled maps for small areas Offline editing and basic attachments Offline TPKs (Tile Packages) Github.com/esri/Offline-editor-js
Offline JS – detect network status github.hubspot.com/offline cordova-plugin-network-information
cordova-plugin-network-information
cordova-plugin-network-information Caveats: Use in addition to Offline.js Mainly benefits Android users iOS can’t detect connection type Emulators may return Connection.UNKNOWN
Offline JS More good info: slides.com/andyg/offline-js andygup.net/web-mobile/
Offline JS Need a full features, robust offline solution? ArcGIS Runtime SDKs Integrated offline support for editing and sync Support for related tables, domains, subtypes and more.
Best practices Monitor & handle offline conditions Protect all HTTP requests Host HTML, CSS, JS and images locally Cache resources when feasible
Use as little memory as possible
Bonus slide – Debugging! Chrome and Safari remote debugging
Andy Gup agup@esri.com @agup