下面是我的代码中实现NSURLConnection sendAsynchronousRequest的一部分,但似乎它没有执行sendAsynchronousRequest数据是nil并且它导致应用程序崩溃。请帮忙解决这个问题
[NSURLConnection sendAsynchronousRequest:nsURLRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSLog(@"data %@", data);
NSMutableDictionary *nsDicResponse = [[NSMutableDictionary alloc] init];
id responseBody = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSInteger responseCode = [nsHTTPUrlCode statusCode];
NSLog(@"response code %d", responseCode);
[nsDicResponse setValue:[NSNumber numberWithInteger:responseCode] forKey:@"HTTPCode"];
[nsDicResponse setValue:[nsError userInfo] forKey:@"HTTPErrorMessage"];
if(nsError==nil) {
[nsDicResponse setValue:responseBody forKey:@"HTTPBody"];
} else {
NSLog(@"Error Found: %@", [nsError userInfo]);
}
block(nsDicResponse);
}];