MonoTouch:如何从URL逐步保存一个巨大的PDF? [英] MonoTouch: How to save a huge PDF downloaded from an URL incrementally?

查看:156
本文介绍了MonoTouch:如何从URL逐步保存一个巨大的PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从我的MonoTouch iPhone / iPad报摊应用程序的URL下载一个巨大的PDF文件。



PDF太大了,无法适应内存,所以我需要使用NSData递增保存。



我的想法如下:而不是在NSData中附加所有下载的数据,而在下载的最后,当我得到所有数据,将其存储到一个文件中,我想在一个单独的线程中异步执行下载,并附加到每个接收到的块的文件并释放我的内存,但确定如果连接被丢弃或应用程序崩溃的下载将自动从最后一个块自动恢复,而不会破坏文件。



你建议什么?有更好的方法吗?如何在MonoTouch中做到这一点?我没有在Xamarin网站上找到关于iOS增量下载/恢复的任何文档或代码示例。

解决方案

可以使用系统.Net.WebClient,并使用DownloadFile方法,它将数据从HTTP流传输到磁盘,而不保留在内存中。


I need to download a huge PDF file from an URL in my MonoTouch iPhone/iPad newsstand app.

The PDF is too big to fit in memory, so I need to save it incrementally with NSData.

My idea is the following: instead of appending all the downloaded data in NSData and at the very end of the download, when I got all data, to store it to a file, I want to execute the download asynchronously in a separate thread and append to a file each received chunk and free my memory, but be certain that if the connection is dropped or the app crashes the download would resume automatically from the last chunk without corrupting the file.

What do you suggest? Is there a better method? How can I do it in MonoTouch? I did't find any documentation or code example about iOS incremental download/resume on the Xamarin website.

解决方案

You can use System.Net.WebClient and use the DownloadFile method, which will stream the data from HTTP to disk, without keeping it in memory.

这篇关于MonoTouch:如何从URL逐步保存一个巨大的PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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