How to show an alert when the server is not working properly?

I am getting list using url by doing parsing it using xml parser. sometimes the server is not working properly. then how to give an alert when server is not working properly. I have given the code below

-(NSMutableArray*)getCustomerList:(NSString *)count category:(NSString *)aCategory alphabetic:(NSString *)alphabeticValue favorite:(NSString *)isFavoriteString
    [self updateStatus];
    if (internetConnectionStatus == NotReachable) 

        UIAlertView *reachbleAlert = [[UIAlertView alloc] initWithTitle:@"message"
                                                                message: @"No network available alert"
                                                      otherButtonTitles: nil];
        [reachbleAlert show];   
        [reachbleAlert release];
        return 0;

        NSString *urlString=@"http:getCustomerList.jsp";
        urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [dataParser parseXMLFileAtURL:[NSURL URLWithString:urlString]];
        NSMutableArray *list =[dataParser getCustomerListFromParser];
        printf("\n url for Customer List%s",[urlString UTF8String]);
        printf("\n Customer List   %d",[list count]);
        return list;

I am sending parameter to url to return repctive list when it returns zero I am dispalying alert in view controller.

but when server is not working properly then how to display this alert.

Please help me out of this.

Thank you, Madan mohan.


In my opinion : First perform the request operation to the server for any response.

Secondly Catch the the response received in a BOOL variable .

Finally when your BOOL variable is TRUE perform the desired operation [Such as parsing..] Otherwise just show an alert message with a proper error message.

I'm sure there's a perfectly nice way to do it with parseXMLFileAtURL. I don't that way.

What I do know is if you use the excellent ASIHTTPRequest library to make an asynchronous request, all of that stuff is taken care of for you. You create two delegate methods, RequestFinished and RequestFailed, and one of them will be called when the result is clear.

In RequestFinished you'd parse the string portion of the response object.

In RequestFailed you'd display the alert and then decide how to proceed from there.

for this u create the asynchronous request usingNSURLRequest

NSURL *theURL=[[NSURL alloc]initWithString:@"**YOUR URL**"]; NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc] initWithURL:theURL]; [theRequest setTimeoutInterval:150]; [theURL release]; mURLConnection=[[NSURLConnection alloc]initWithRequest:theRequest delegate:self]; [theRequest release]

and then in their delegate method

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 


if (mResultData == nil) //mResultData is NSData(member variable) 
    mResultData = [[NSMutableData alloc] init];
[mResultData setLength: 0];


-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {

[mResultData appendData:data];  


// this method calls if their is any problem from server side -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { [mResultData release]; mResultData = nil; [mURLConnection release]; mURLConnection = nil; //here the show the error UIAlertView *theAlert=[[UIAlertView alloc]initWithTitle:kAlertTitle message:[error localizedDescription] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [theAlert show]; [theAlert release]; }

  • (void)connectionDidFinishLoading:(NSURLConnection *)connection {

    //here u could send mResulData for parsing // create NSXMLParser


Need Your Help

Objective-C IOS Xcode: Unable to modify object in NSMutableArray

ios objective-c xcode nsmutablearray

My problem is that I have a class property that is of type NSMutableArray, as defined in my header file, yet when I attempt to modify one of the array elements (an NSDictionary) I receive the follo...

Highlight active link when using scrollto based on current view

jquery scrollto

I have a website which is one page and the user navigates to each section using links which uses the scrollto jquery plugin.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.