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

2019-09-08 18:27发布

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条回答
唯我独甜
2楼-- · 2019-09-08 19:04

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 !

查看更多
登录 后发表回答