Caching pictures
Is it possible to cache images that is loaded externally on the iPhone so that they dont have to be loaded again next time?
2 Answers
-
If you load the image using Ti.Network.createHTTPClient(), you could save the images on the device on the onload callback with:
var f = Ti.Filesystem.getFile(sUrl);
f.write(this.responseData);…f.nativePath is the location of the image.
-
Here is an example of coding:
var f = Ti.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,issue); var wv = Ti.UI.createWebView({ bottom:0, left:0, top:0, backgroundColor:'black' }); if (f.exists()) { wv.url= f.nativePath; w.add(wv); w.add(unpdfButton); } else { c = Titanium.Network.createHTTPClient(); c.setTimeout(60000); c.onload = function() { wv.url= f.nativePath; w.add(wv); }; c.ondatastream = function(e) { pb.value = e.progress ; }; c.onerror = function(e) { Ti.API.info('XHR Error ' + e.error); }; // foo: c.open('GET','http://www.hamburg.***.de/uploads/media/' + issue); // bar: c.file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,issue); c.send(); }