Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
716 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 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...