2012-10-10 21 views

答えて

14

エラーが発生した場合、エラーパラメータが返されたときにエラーパラメータは非ゼロになります。

[NSError code]が返す値をチェックすることでエラーコードを取得できます。タイムアウトのエラーコードはNSURLErrorTimedOutです。例えば

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

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

アラートをユーザに提示し、sendSynchronousRequest:returningResponse:error:のエラーパラメータをアラートのメッセージに渡すことができます。

コードは次のようになります:

[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]; 
} 

はそれが役に立てば幸い!

関連する問題