2012-10-10 11 views

risposta

14

Se si è verificato un errore, il parametro di errore sarà diverso da zero quando viene restituito sendSynchronousRequest:returningResponse:error:.

È possibile recuperare il codice di errore controllando il valore restituito da [NSError code]. Il codice di errore per timeout è NSURLErrorTimedOut.

Per esempio:

NSError *error = nil; 
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error] 

if (error.code == NSURLErrorTimedOut) { 
// Handle time out here 
} 
0

È possibile presentare un avviso all'utente e passare il parametro di errore in sendSynchronousRequest:returningResponse:error: al messaggio dell'avviso.

il codice sarà qualcosa di simile:

[NSURLConnection sendSynchronousRequest: req returningResponse: &response error: &error]; 

if (error) 
{ 
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
[alert show]; 
} 

Speranza che aiuta !!

Problemi correlati