开发者

Mobile Safari application cache bugs?

开发者 https://www.devze.com 2023-01-04 01:04 出处:网络
I\'m using Mobile Safari\'s cache manifest file to store a multi-page data entry application that is run on an iPod Touch (version 3.1.3) in offline mode. The application writes to the client-side dat

I'm using Mobile Safari's cache manifest file to store a multi-page data entry application that is run on an iPod Touch (version 3.1.3) in offline mode. The application writes to the client-side database by way of the persistence.js ORM. This all works fine.

However, I run into the occasional, extremely hard to reproduce problem whereby Safari just seems to forget that the pages are cached. When this happens, the "Cannot Open Page" alert appears, which is the same one that comes up when you attempt to visit a non-cached website with the wi-fi turned off. The only way that I've found to fix this is to reconnect to a wireless signal and visit the site while online, which seems to set the cache straight. This is easy to do when you're in the office, but not so easy to do out in the field.

I'm not trying to reference anything outside of the cached resources, and I've verified that the application is cached by running through th开发者_运维知识库e entire site while disconnected, sometimes successfully for days on end. I feel like there's a bug in the OS that messes with the validity of the cache. I'm not necessarily looking for a solution to the problem (but that would be nice), but rather just some confirmation that others have encountered this problem.


Using a cache manifest and lot of troubleshooting, I am able to reliably cache an entire application; Do note that this is a single page app with only a few separate file resources.

As a further enhancement, I have been trying to modify the DOM based on

window.applicationCache status

to inform the user about updates, ie:

tap here to apply update

If that were possible, I could swap the cache

window.applicationCache.swapCache();

Which would allow me to swap in the updated cache and then restart the page to provide a streamlined update mechanism.

Potentially even more streamlined than apps from the apple store.

I suspect that the applicationCache API was hamstrung by Apple to hinder web apps for this very reason. Having said that, I believe the level of support for "html5" APIs on mobile devices is among the most robust in apple's safari.

Following are a few problems I have noticed so far, in no particular order. Please note that this is not a comprehensive list of bugs.

I never get an 'updateready' event; this alert line never runs:

window.applicationCache.addEventListener('updateready', function(e) {
    alert('updateready event status=' + window.applicationCache.status );
}, false);

I can not manually check for updates. The following code gives me an exception

    try{
        window.applicationCache.update();
    }catch (err){
        alert('exception:\n' + err);
    }

It seems that as soon as I start to interact with the cache state at all, the caching stops working. The bugs are fiendishly elusive; pinning down & isolating any one issue can take a lot of time, especially since all this code runs flawlessly on other browsers (chrome).

Now here's a good one: I suspect that if you pin an app to your home screen, iCloud "backs up" resources and restores them after you run the app for the first time from the home screen. To avoid this issue, you may sometimes have to rename files. I have proven that apple makes discrete backups of obsolete components by

removing them entirely from my app server

deleting the pinned web apps from home screen

clearing all the caches

opening the app url in safari

verify that its the newest version

pin to home

verify that the pinned app the newest version

close it

run again - and its back to the old one, no longer on your server.

Finally, if you run the pinned app while the phone is in airplane mode, iCloud will not be able to restore the obsolete files. This proves that it's coming from over the air.

0

精彩评论

暂无评论...
验证码 换一张
取 消