将大文件从网络下载到iPhone以写入磁盘的最佳方式 [英] Best way to download large files from web to iPhone for writing to disk

查看:100
本文介绍了将大文件从网络下载到iPhone以写入磁盘的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone应用程式中,我目前有将档案从网路下载到iPhone并储存到磁碟的程式码。



问题是如果档案 然后应用程序的内存使用情况和应用程序崩溃。



我相信我只是没有做 。



目前我有以下:

  mediaData = [[ NSData alloc] initWithContentsOfURL:[NSURL URLWithString:path]]; 
[mediaData writeToFile:fullPath atomically:YES];
[mediaData release];

正如我所说,这适用于像图片,但不是像一个视频剪辑,作为应用程序崩溃。



这是正确的方法,以防止我的应用程序崩溃?



感谢

div class =h2_lin>解决方案

您可以使用 NSURLConnection ,它以异步方式运行,并以可管理的块传递数据。


In an iPhone app I currently have code for downloading a file from the Web to the iPhone and saving it to disk.

The problem is that if the file is large then the memory usage of the app skyrockets and the app crashes.

I am sure I am just not doing it the "proper" way.

Currently I have the following:

mediaData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:path]];
[mediaData writeToFile:fullPath atomically:YES];
[mediaData release];

As I mentioned this works for something like a picture, but not for something like say a video clip, as the app crashes.

What is the proper way to do this to keep my app from crashing? My thought was maybe sockets, but as I have not done much socket programming, I am not sure.

Thanks

解决方案

You can use NSURLConnection which runs asynchronously and delivers data in manageable chunks.

这篇关于将大文件从网络下载到iPhone以写入磁盘的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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