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

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...