如何在iPhone内存中保存pdf文件,并使用钛的pdf文件开启应用程序访问它 [英] How to save a pdf file in iPhone memory and make it accessible by pdf file opener applications using titanium

查看:197
本文介绍了如何在iPhone内存中保存pdf文件,并使用钛的pdf文件开启应用程序访问它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是我的应用程序中的钛的新bie我需要使用钛下载并在iOS中保存pdf文件,下载的文件可以通过第三方pdf查看器应用程序访问。任何帮助都可以提前实现这一点。

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-确保您的网络服务返回PDF文件。

1- Make sure your webservice returns a PDF file.

2 - 使用FileSystem管理文件

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();

现在你使用pdf查看器并从我在Android上测试的externalStorageDirectory
打开PDF ,它的确有效!

Now you use a pdf viewer and open the PDF from the externalStorageDirectory I tested on Android, it works !

这篇关于如何在iPhone内存中保存pdf文件,并使用钛的pdf文件开启应用程序访问它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆