PhoneGap - Issues• Tries to cover too much ground• Overly complex• Excessive amount of code• Slow (due to the above)• Many features already in WebKit• Breaks SproutCore !
The Project• SI Magazine• Reader app, rich UI• Support various content types• Run on iPhone and Android• Limited JS-native needs
Project Needs• Access to Native Debug console• Secure off-line storage and caching of data• 2-way JS-native Bridge with callbacks• Change native controls based on JS UI changes• Ability to execute select native commands
Problems• PhoneGap does not work (well) with Sproutcore • Uses custom URL schemes on iOS to send commands to native • Causes split second loss of access to DOM • Sproutcore blows up silently during rendering and stops the app
More Problems• Works differently on Android • Uses a long-polling AJaX server (?!?!)• Bloat (!) - too many features• Slowdowns• Too much complexity
Solutions• Step 1: on iOS change transport layer• Step 2: remove 99% of PhoneGap• Step 3: Keep it simple
iOS• Used SC.Request instead of window.location.url• Intercepted psuedo-XHR requests in iOS default cache• Rewrote requests and redirected to PG command infrastructure
iOS Details• Extend NSURLCache• Override cachedResponse method to intercept URLs• Used http://gap/... instead of gap://....• New JS-to-Native API + callback support