【问题标题】:How to save a pdf file in iPhone memory and make it accessible by pdf file opener applications using titanium如何将 pdf 文件保存在 iPhone 内存中,并通过使用钛的 pdf 文件打开器应用程序访问它
【发布时间】:2012-12-10 08:57:49
【问题描述】:

我是我的应用程序中钛的新手,我需要使用钛在 iOS 中下载并保存一个 pdf 文件,第三方 pdf 查看器应用程序可以访问下载的文件。提前感谢任何帮助。

【问题讨论】:

标签: iphone ios ipad titanium-mobile


【解决方案1】:

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 上测试过,它可以工作!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-16
    相关资源
    最近更新 更多