objective c - iOS Cache a UIWebView -


i've written ios app loads html5 web application inside uiwebview. i'm trying make app cache in uiwebview use while on 3g connection rather load again.

it needs follow links while on wifi connection , download pages , images. when on 3g connection should load cache.

is possible? ideas on should start? need make html5 application load pages in background rather have app it?

thanks help!

firstly use reachability detect if there wifi connection , server accessible. way can handle both 3g connectivity , no internet connection in same way. (accessing cached pages). means can use cache if have wifi still cannot reach server.

reachability sample code

i either download zip file of web pages , associated assets (if static website) , unzip , store them in local file system. can point uiwebview local directory when there not wifi.

you use zip archive handle this

ziparchive github page

if not option html page when load in uiwebview. problem doing reliant on user accessing pages in order cache them.

you can use html code , store locally:

 // determile cache file path nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *filepath = [nsstring stringwithformat:@"%@/%@", [paths objectatindex:0],@"index.html"];     // download , write file nsurl *url = [nsurl urlwithstring:@"http://www.google.co.uk"]; nsdata *urldata = [nsdata datawithcontentsofurl:url]; [urldata writetofile:filepath atomically:yes];  // load file in uiwebview [web loadrequest:[nsurlrequest requestwithurl:[nsurl fileurlwithpath:filepath]]]; 

you use code web pages in background well. either need hard code required urls , them individually or better still download list of web pages site first.

you create web service (json best option this) giving list of urls download. parse through json , use urls feed code above , cache html locally.

just remember careful hyperlinks , links images , css within html break cached website if looking full online url rather relative path.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -