我正在设置一个NSURLConnection来访问远程服务器:
NSURL *url = [[NSURL alloc] initWithString:projectURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
使用以下代理方法:
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse
所有这些方法都说“在iOS 2.0至iOS 4.3中可用”。我的问题应该是针对当前的iOS5做另一种方式吗?我需要异步传输,需要通过NSURLCredential进行UID / PWD身份验证。
因此,如果我在我的标题中采用协议<NSURLConnectionDelegate>
并使用上面的委托方法,我会以正确的方式执行此操作吗?
答案 0 :(得分:4)
对于iOS 5,看起来您可以利用新的NSURLConnectionDelegate
protocol(为您链接的文档)。
And here's a related (or maybe even duplicate?) question that explains even better