问题
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