简体   繁体   中英

Internet connection unavailable message for iPhone app

I have an application that needs to load its data from the server when it first launch, i want to add a message that alert user in case the internet connection is not active as it is done right now it crashes when there's no connection. Thank you.

If its related to failing internet connection you can use one of the NSURLConnectionDataDelegate methods:

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{

UIAlertView*aview=[[UIAlertView alloc]initWithTitle:@"Connection Failed" message:@"Please check your internet connection" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil ];
[aview show];
[aview release]; // Notify the user about the failure.

NSLog(@"Reason:%@",[error description]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM