NSURLConnection sendAsynchronousRequest似乎无法正常工作

时间:2013-09-17 18:46:08

标签: ios objective-c nsurlconnection null sendasynchronousrequest

下面是我的代码中实现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);
}];

0 个答案:

没有答案