How to save a pdf file in iPhone memory and make it accessible by pdf file opener applications using titanium

血红的双手。 提交于 2020-01-17 01:16:06

问题


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 !



来源:https://stackoverflow.com/questions/13797712/how-to-save-a-pdf-file-in-iphone-memory-and-make-it-accessible-by-pdf-file-opene

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!