开发者

URLCache - iPhone SDK

开发者 https://www.devze.com 2022-12-27 19:46 出处:网络
I need some help in using the NSURLCache to download a simple file. It would need t开发者_开发技巧o be saved in the Documents folder of the app. I have seen the URLCache example that apple presented,

I need some help in using the NSURLCache to download a simple file. It would need t开发者_开发技巧o be saved in the Documents folder of the app. I have seen the URLCache example that apple presented, but I didn't find it useful since it was an image that was being shown. In addition there was some complex code on the modification date. I actually need something when the application opens it will begin the download process. Can someone guide me through just the download process of any file?

Thanks

Kevin


NSURL *myURL = [NSURL urlWithString:@"http://www.google.com/theInternet.zip"];
NSData *myData = [NSData dataWithContentsOfURL:myURL];

[myData writeToFile:@"ThePath" atomically:YES];

This will block, but should be ok for small downloads. If you are going to be downloading something that is many megabytes then look into asynchronous downloads. You can see an example here:

http://github.com/erica/iphone-3.0-cookbook-/tree/master/C13-Networking/07-Asynchronous%20Downloads/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号