Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
719 views
in Technique[技术] by (71.8m points)

cocoa touch - Best way to download large files from web to iPhone for writing to disk

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...