URLCache - iPhone SDK

发布于 2024-08-29 22:14:17 字数 186 浏览 8 评论 0原文

我需要一些帮助来使用 NSURLCache 下载一个简单的文件。它需要保存在应用程序的文档文件夹中。我已经看过苹果提供的 URLCache 示例,但我发现它没有用,因为它显示的是图像。另外修改日期上还有一些复杂的代码。我实际上需要一些东西,当应用程序打开时它将开始下载过程。有人可以指导我完成任何文件的下载过程吗?

谢谢

凯文

I need some help in using the NSURLCache to download a simple file. It would need to 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漫漫岁月 2024-09-05 22:14:17
NSURL *myURL = [NSURL urlWithString:@"http://www.google.com/theInternet.zip"];
NSData *myData = [NSData dataWithContentsOfURL:myURL];

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

这会阻塞,但对于小量下载来说应该没问题。如果您要下载很多兆字节的内容,请考虑异步下载。您可以在此处查看示例:

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

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文