Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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?

— asked March 26th 2010 by Martin Krafft
  • image
  • iphone
0 Comments

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.

    — answered March 29th 2010 by Alexander van der Werff
    permalink
    0 Comments
  • 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();
                }
    
    — answered June 30th 2011 by Rainer Schleevoigt
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.