我正在使用Foundation网络API进行一些实验,我正在尝试下载文件。
所以我创建了一个NSURLRequest
:
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.mysite.it/something.something"]];
现在我有一个问题NSURLConnectionDownload.I必须实现这个方法
- (void)connection:(NSURLConnection *)connection didWriteData:(long long)bytesWritten totalBytesWritten:(long long)totalBytesWritten expectedTotalBytes:(long long)expectedTotalBytes
在连接时我创建了一个NSURLConnection对象,但我不知道我必须实现哪些方法......有什么建议吗?
答案 0 :(得分: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。希望它能帮助你!