Many companies are looking for every opportunity to save time and money building and deploying mobile apps across multiple platforms. Such has been the promise of HTML5-centric apps and hybrid app deployment frameworks like Phone Gap and Appcellerator’s Titanium. These platforms aren’t the silver bullets that everyone wants them to be, though in certain circumstances they are a very good fit.
However, there was a significant, but not widely reported change in iOS 5.1 that breaks many hybrid web apps. The embedded WebView HTML5 applications to be packaged within a native application, enabling the distribution of web apps to native app stores. This is the primary method by which tools from PhoneGap, Titanium or Sencha create ‘native’ apps across multiple platforms using a single HTML5-centric code base.
Sencha’s HTML5 Scorecard for iOS 5.1 and the new iPad sums up the crux of the problem quite well:
Prior to iOS 5.1, when an embedded WebView was used, data stored locally using HTML5 storage was kept persistent. Specifically, if your application used localStorage or WebSQL, it was considered part of the application’s data. When a new version of the app was installed or the app was hard-closed, the persistent data was kept around. The next time the app started, the localStorage would appear as if it had never gone away, exactly as what happens in Mobile Safari.
In iOS 5.1, this data is no longer considered persistent and is treated as temporary or transitory data, so iOS can destroy it at any time, without warning, including during low memory scenarios. This is probably because Apple can’t reliably iCloud backup, or iCloud sync from anything that’s not stored in the native CoreData storage. As such, they’re pushing developers to move to Apple native data systems to make apps iCloud-ready. Of course not everybody will want to do this. For developers who relied on localStorage or WebSQL as their mechanism to store data in their app, breaking this mechanism is a big deal.
Alas, there are no easy fixes. On the PhoneGap Community Support forums, a PhoneGap employee suggests using their File API to address the issue. However that causes other problems for Android and other platforms. So tread carefully.