error handling with NSURLConnection sendSynchronousRequest

前端 未结 2 2029
无人共我
无人共我 2020-12-05 01:06

how can i do better error handling with NSURLConnection sendSynchronousRequest? is there any way i can implement

- (void)connection:(NSURLConnection *)aConn          


        
2条回答
  •  失恋的感觉
    2020-12-05 01:25

    -sendSynchronousRequest:returningResponse:error: gives you a way to get an error right there in the method itself. That last argument is really (NSError **) error; that is, a pointer to an NSError pointer. Try this:

    NSError        *error = nil;
    NSURLResponse  *response = nil;
    
    [NSURLConnection sendSynchronousRequest: req returningResponse: &response error: &error];
    
    if (error) {...handle the error}
    

提交回复
热议问题