0
The answer to my original question使用以下代碼。使用Apple推薦的NSURL代理方法
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:self.urlNameInput.text] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[NSURLConnection sendAsynchronousRequest:theRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *connection, NSData *data, NSError *error){...}];
我原來的代碼沒有工作,但如下。我的代碼使用了Apple Docs中建議的一組委託方法(connection:didReceiveResponse:,connection:didReceiveData:,connection:didFailWithError:and connectionDidFinishLoading :)。
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:self.urlNameInput.text] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
receivedData = [NSMutableData data] ;
} else {
// Inform the user that the connection failed.
NSLog(@"Their is an error with that URL.");
};
委託方法是否與建議的代碼兼容,如果是,我如何將它們集成到建議的代碼中?