将 NSData 附加到 Objective C 中的文件

发布于 2024-08-01 14:22:21 字数 302 浏览 4 评论 0原文

我正在尝试在 iPhone 上下载一个大文件,并在下载时将其保存到磁盘。

理想情况下,在:

-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data {

}

我想将“数据”附加到磁盘上的文件中。

我已经查看了 NSData 文档。 有可以写入文件的函数,但我看不到任何可以附加到现有文件的内容。

有谁知道我如何附加这些数据? 非常感谢任何帮助! 缺口。

I'm attempting to download a large file on the iPhone and save it to disk as it is downloaded.

Ideally, in:

-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data {

}

I want to append 'data' to a file on disk.

I've checked out the NSData documentation. There are functions to write to a file, but I can't see anything to append to an existing file.

Does anyone know how I can append this data? Any help much appreciated!
Nick.

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

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

发布评论

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

评论(2

白云不回头 2024-08-08 14:22:21

您可以结合使用 NSFileHandle 类中的 -writeData:-seekToEndOfFile 方法将 NSData 写入末尾一个文件的。

You can use a combination of -writeData: and -seekToEndOfFile methods from NSFileHandle class for writing NSData to the end of a file.

可是我不能没有你 2024-08-08 14:22:21

有一个 Apple 示例应用程序下载到文件,使用 NSOutputStream 写入文件。 查看名为“SimpleURLConnections”的示例应用程序的文件“GetController.h”。

这是一个直接的 URL——尽管我认为如果您没有登录到developer.apple.com,它就不会起作用。

https:// developer.apple.com/library/ios/#samplecode/SimpleURLConnections/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009245

There's a Apple sample app that downloads to a file, using NSOutputStream to write to the file. Look in file "GetController.h" of the sample app called "SimpleURLConnections".

Here's a direct URL -- although I don't think it'll work if you're not logged into to developer.apple.com.

https://developer.apple.com/library/ios/#samplecode/SimpleURLConnections/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009245

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