iOS Clears HTML5 Offline Cached Data - ios

We developed an offline HTML5 web-app using the .manifest caching mechanism. Everything works as expectet.
Now some of our customers complain that after a long period of offline usage the cached data suddenly disappeared. It turns out - this is my guess - that iOS stores the cached files in its /CACHES/ directory, which, since iOS 5.0, can get purged if the device gets out of space. This can happen anytime, without even a warning to the user. Hence, the offline webapp is no longer running properly. The user has to reconnect the device to the internet and update the app.
For native Apps this problem is solved by storing the files in the /DOCUMENTS/ dir, using the flag 'do not backup' which prevents the files from being purged (since they don't sit in the /CACHES/ dir, and are not backed up to iCloud or iTunes.
See this link for details: http://www.marco.org/2011/10/13/ios5-caches-cleaning, however this does not say anything about HTML5 caching...
This one explains it again, however no solution: http://www.moneytoolkit.com/2012/04/apple-ios-html5-localstorage-is-broken/
Has anyone experienced the same? Is there a solution to this? The goal is to install a web-app once, and then run it without connection 'forever'...
Cheers, pawi

There is no way around this in Safari. A cache is never considered to be permanent.
If you have a UIWebView inside a native app, you can set WebKitStoreWebDataForBackup to YES in your user defaults. (iOS 6+ only)

Related

PWA Android and IOS Cache

We are experiencing a pwa application with services worker and everything that surrounds this theme.
I have questions about cache. Information is currently cached and accessed when offline. This works well when we talk about Android. In IOS it seems that the cache is not shared when we add the application to the home screen (installed). It seems that IOS keeps a cache for the application accessed in Safari and the installed one (I'm talking about the same application). In android it seems that the same cache is shared for the version installed and accessed in chrome.
In IOS after adding the home screen I am forced to log in online to generate the installed application cache.
About IOS would you like to know if you have already gone through this? And what would be the best way to persist this data so that the same cache is shared in the application accessed in Safari and the installed version.
In the service worker you mention the name of the cache, until and unless you change it there or update it e.g;
const staticCacheName = 'pages-cache-v3'; it will remain same and will be shared among versions. This may be true for the Android am not sure about IOS. Please update me if you have already found a better answer. Cheers:)
If this is still relevant, then I think that you should look at my answer in this question, because you are faced with the same problem.
PWAs on iOS 12 no longer shares Service Worker cache with Safari?

iOS 7 webview and localStorage persistence

I'm developing a hybrid app (for iOS and Android only) using PhoneGap/Cordova and want to use HTML5 localStorage to store content for offline access.
http://caniuse.com/#search=localStorage says - "In iOS 5 & 6 localStorage data is stored in a location that may occasionally be cleared out by the OS."
What is the situation with an iOS 7 (and later) webview, in what cases will localStorage persist, or get cleared out (by the OS, or the user)?
Will an update to the app clear localStorage?
What about the user clearing browser history on Safari - will that apply to the webview too?
Do I need to worry (or can I even control) where on the fils system the localStorage is created. I understand it should not be backed up on iCloud.
I got a device (iPad) and checking the file system I see that localStorage file is in ~/Library/Caches within the app sandbox, see image below.
From the docs:
https://developer.apple.com/icloud/documentation/data-storage/index.html
Data that can be downloaded again or regenerated should be stored in the /Library/Caches directory. Examples of files you should put in the Caches directory include database cache files and downloadable content, such as that used by magazine, newspaper, and map applications.
I am simply doing this to set data:
localStorage.setItem('foo','this is the FOO value');
localStorage.setItem('bar','and this is the BAR value');
If you do still face the issue with Cordova-iOS v4 , then try the NativeStorage plugin. https://www.npmjs.com/package/cordova-plugin-nativestorage.
It has set, put and get functions which implement platform capabilities like android shared preferences and iOS NSUserDefaults which makes data store as safe as allowed.
cordova plugin add cordova-plugin-nativestorage
NativeStorage.putObject("reference_to_value",<object>, <success-callback>, <error-callback>);
NativeStorage.getObject("reference_to_value",<success-callback>, <error-callback>);
If you are using cordova, that problem was fixed long time ago, even for iOS 5 and iOS 6. You shouldn't worry if you are using the latest version of cordova.
Your best bet is to use the NativeStorage plugin:
https://www.npmjs.com/package/cordova-plugin-nativestorage
To answer your questions:
The localStorage data is kept in a cache directory in the filesystem, and cache is cleaned by the OS frequently (for example when the device is low on disk space).
No, updating the app won't clear local storage.
No, Safari local storage and Webview local storage are separate.
No, you cannot control where on the filesystem it's stored.

Offline iOS7 web app: doesn't update manifest

I have written a web app for offline usage on iOS7 safari and, while it does download the files in the manifest for offline usage, it never updates cached files when the manifest changes.
I have a php script that loops through files in a directory and creates a cache.appcache file. It also adds a comment that is a md5 of the files so that each time a file changes, the cache.appcache file will update.
This works fine on desktop chrome and the app cache update is triggered. However, on the iPad it never tries to update the cache: I have to clear the device's cache manually to get the updated app.
Is there something I'm missing?
http://html5doctor.com/go-offline-with-application-cache/#trigger-refresh
Updates in the cache.manifest file are supposed to trigger cache updates. This was happening on desktop browsers but not on the iPad.
For future reference this appeared to be caused by a combination of iOS 'web app' mode and the HTTP Auth password I had on the page. It seems that this combination prevented the cache update check because it worked fine in regular iOS safari but only worked in both after I removed the password.

Is there a way to not erase the documents directory when uninstalling the app?

I'm developing an AIR app for iPad, and I found that when I uninstall the app, the documents directory data gets erased, is there a way to keep this data even when I delete the app or this behavior is regulated by iOS and there is nothing I can do about it?.
Thanks.
No you cant
From The iOS Environment
For security reasons, iOS places each app (including its preferences and data) in a sandbox at install time. A sandbox is a set of fine-grained controls that limit the app’s access to files, preferences, network resources, hardware, and so on. As part of the sandboxing process, the system installs each app in its own sandbox directory, which acts as the home for the app and its data.
So you delete the application all the content regarding that particular app gets deleted.
as soon app get uninstalled the document directory folder also get deleted with that. Although you will not able to access that folder from other apps so there is no need to keep that.

iOS: Did Apple disable HTML5 offline capability for web apps saved to the home screen?

I've been doing lots of work in getting a few web apps to work offline on iOS using the HTML5 manifest. I've ran across the typical problems everyone else has and fixed them and everything seems to be working fine—except in the case where I save the web app to the desktop on my iPhone 4.
If I do this and then enable airplane mode, I get the following alert when trying to access the app via the home screen: "your-app-name could not be opened because its not connected to the internet." Accessing the app via Safari browser works fine while offline.
If anyone knows if this is an error on my part, or even the slim possibility of a work around, do tell.
Even downloading the new Financial Times web app (very well done with extensive localStorage support) results in an error when accessing it offline from the home screen.
Technical specs: Running iPhone 4 with iOS 4.3.3 (but also saw the issue in 4.3.2)
After reading the comments (especially Rowan's) I ran more tests and found the answer:
No, Apple did not disable HTML5 offline capability for web apps saved to the home screen, it works - for the most part. There is a bug that will make it not work. It doesn't seem to have anything to do with your manifest setup (unless perhaps it downloaded a bad manifest or incomplete manifest at one point.) We don't know how widespread it is but the fix is to clear your Mobile Safari Cache.
Here's the steps:
Close the web app (make sure its not sticking around in the background).
Cleared Mobile Safari cache: Settings > Safari > Clear Cache
Reopened the app (for caching).
Close the web app again (make sure its not sticking around in the background).
Enabled "Airplane Mode": Settings > Airplane Mode
Reopened the app.
It should now work offline. If it doesn't then its probably a separate manifest issue in your app. Looks like a weird bug with the browser cache - or perhaps the cache was completely full? Who knows, but that's the answer. Thanks guys.
iOS seems to be very sensitive to load issues when offline.
I was getting your "could not be opened" error when offline on a page I was working on. The problem turned out to be that the page created an iframe pointing to a site that didn't have an AppCache. Removing those iframes fixed the issue.
In my case, I handled it using window.navigator.standalone which tells you whether you're running in an iOS homescreen app. The code looked like this:
if (!navigator.standalone) insertFrames();
add this to your html:
https://web.archive.org/web/20170201180939/https://jonathanstark.com/blog/debugging-html-5-offline-application-cache?filename=2009/09/27/debugging-html-5-offline-application-cache/
I found it massively useful - even though I've created my manifest file and compared it to other people's manifests this JavaScript debugging script gave me the clue I would have never found otherwise. I apparently had syntax error in my manifest ... long story short I had to remove everything and add the paths to each file/image one by one. The end result was the same however it worked... how weird!!! does whitespace / comments affect the syntax of the file?

Resources