[英]NSURLConnection sendAsynchronousRequest:queue:completionHandler not working in iOS 4.3
[英]connectionDidFinishLoading: not called with the use of [NSURLConnection sendAsynchronousRequest: queue: completionHandler:
当[NSURLConnection sendAsynchronousRequest:的答案得到良好的状态代码时,我想用NSMutableURLRequest启动一个请求。 当我启动仅包含NSMutableURLRequest的executeForStatusOkMetod时,它可以完美运行。
但是,如果我使用[NSURLConnection sendAsynchronousRequest:来启动executeForStatusOkMetod ,则永远不会调用connectionDidFinishLoading:函数。
这是主要代码:
NSOperationQueue *myQueue = [[NSOperationQueue alloc] init];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
request.timeoutInterval = 10;
[NSURLConnection sendAsynchronousRequest:request queue:myQueue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"response status code: %ld, error status : %@", (long)[httpResponse statusCode], error.description);
if ((long)[httpResponse statusCode] >= 200 && (long)[httpResponse statusCode]< 400)
{
// do stuff
[[DataManagement sharedManager] executeForStatusOkMetod];
}
}];
这是称为的功能:
(void) executeForStatusOkMetod
{
NSMutableURLRequest* request = [[NSMutableURLRequest alloc] init];
NSString *url_string = [bytes stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[request setURL:[NSURL URLWithString:[set_send_order stringByAppendingString: url_string]]];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[request setTimeoutInterval:timeOut];
[NSURLConnection connectionWithRequest:request delegate:self];
}
为什么connectionDidFinishLoading:方法:不与位于[NSURLConnection的sendAsynchronousRequest的NSMutableURLRequest的呼唤叫什么?
在第一个示例中,未调用委托方法,因为API不包含用于设置委托的参数。
在带有完成处理程序的API中,执行完成处理程序时,连接即完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.