Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pre-populate HTML5 offline appcache for a UIWebView in an iOS application

Is it possible to create a UIWebView that has an HTML5 offline appcache pre-populated so that it will work offline even if it is the first time the user is accessing the UIWebView?

If so, how?

I know I can achieve this through other mechanisms, but the above is my first choice. And I'm just plain curious if it's possible.

I'm seeing nothing about it in the documentation.

like image 371
Trott Avatar asked Nov 14 '11 18:11

Trott


2 Answers

What you are looking for is two files in your cache folder.

ApplicationCache.db and cache.db

They both reside in Library/Caches/[your bundle identifier] folder for your application, which you have full access. You can add pre populated cache data to you bundle, and simply copy it to caches folder on you app launch.

BTW you can play with them easily, as they are simple, SQLITE db's.

I hope this helps

like image 171
Deniz Mert Edincik Avatar answered Oct 11 '22 11:10

Deniz Mert Edincik


I think this may reduce to a question of whether you can programmatically write to the UIWebView's cache file (which is to say, whether the UIWebView cache resides within your app's sandbox) – if you can't, then game over. If you can, then it becomes a question of what happens after you drop a pre-populated cache file into place, and whether the UIWebView is "fooled" into thinking that it's already downloaded and cached your HTML5 content.

If you're using the iPhone Simulator to test your app, look in ~/Library/Application Support/iPhone Simulator/5.0/Applications (replace "5.0" with your iOS version, if necessary). You should see a long string of hex digits for each app you've compiled in the simulator; find the one that corresponds to your app, and then look in the Library/Caches/[your app's identifier] subfolder for a file named Cache.db.

This may be the place where UIWebView stores its cache data. If it isn't, game over and the answer to your question is "no, that's not possible". If it is where UIWebView caches data, then it may be possible to populate this Cache.db file in the simulator, grab the file, store it in your app bundle, and then write the cache to the appropriate location when it's time to pre-populate the cache.

At any rate, that's the line of attack I'd use to determine whether it's possible – I'm pretty confident the answer is going to be "no, not possible" unless it turns out the UIWebView cache does reside in your app's sandbox, is writable by you, and you can fool UIWebView by replacing its cache file.

like image 26
Scott Forbes Avatar answered Oct 11 '22 10:10

Scott Forbes