How to save a pdf file in iPhone memory and make i

2019-09-08 18:55发布

问题:

i am new bie to titanium in my app i need to download and save a pdf file in iOS using titanium and the downloaded file can be accessible by third party pdf viewer applications.any help to achieve this thanks in advance.

回答1:

1- Make sure your webservice returns a PDF file.

2- Use the FileSystem to manage your files

var xhr = Titanium.Network.createHTTPClient({
    onload : function() {

        var f = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, 'file.pdf');
        f.write(this.responseData);

        tmpFile = Ti.Filesystem.createTempFile();
        var newPath = tmpFile.nativePath + "." + f.extension();
        Ti.API.info("newPath: " + newPath);
        tmpFile = Ti.Filesystem.getFile(newPath);
        tmpFile.write(f.read());

    },
    timeout : 10000
});
xhr.open('GET', 'your webservice');
xhr.send();

Now you use a pdf viewer and open the PDF from the externalStorageDirectory I tested on Android, it works !