【发布时间】:2012-12-10 08:57:49
【问题描述】:
我是我的应用程序中钛的新手,我需要使用钛在 iOS 中下载并保存一个 pdf 文件,第三方 pdf 查看器应用程序可以访问下载的文件。提前感谢任何帮助。
【问题讨论】:
标签: iphone ios ipad titanium-mobile
我是我的应用程序中钛的新手,我需要使用钛在 iOS 中下载并保存一个 pdf 文件,第三方 pdf 查看器应用程序可以访问下载的文件。提前感谢任何帮助。
【问题讨论】:
标签: iphone ios ipad titanium-mobile
1- 确保您的网络服务返回 PDF 文件。
2- 使用文件系统管理您的文件
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();
现在您使用 pdf 查看器并从 externalStorageDirectory 打开 PDF 我在 Android 上测试过,它可以工作!
【讨论】: