0

我正在对 Foundation 网络 API 进行一些实验,并且正在尝试下载文件。所以我创建了一个NSURLRequest

NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.mysite.it/something.something"]];

现在我有一个问题 NSURLConnectionDownload。我必须实现这个方法

- (void)connection:(NSURLConnection *)connection didWriteData:(long long)bytesWritten totalBytesWritten:(long long)totalBytesWritten expectedTotalBytes:(long long)expectedTotalBytes

在连接时,我创建了一个 NSURLConnection 对象,但我不知道我必须实现哪些方法......有什么建议吗?

4

1 回答 1

0

如果您使用 NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];,您可能需要实现 3 种方法:

  - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
  - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;
  - (void)connectionDidFinishLoading:(NSURLConnection *)connection;

有可能

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;

我建议你看看这里:https ://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html 。希望它有所帮助!

于 2013-02-16T19:23:49.130 回答