request time out and specifed server couldn't be found
I am seeing this wired problem where when i launch my app i get continuous(4-5 times) error message sometime it says
"data connection cannot be established since a call is currently active" there is no active call
The request timed out
A server with the specified hostname could not be found.
and when you click ok, couple of times the error message goes away and the app works without any problem.
I am doing two things when the app launches, i start updating the current location using the CLLocationManager and once i get the location I make two async call using NSURLConnection, i see that didFailWithError method in 开发者_JS百科my NSURLConnection delegate method getting called, all the message comes from there, so what i am trying to figure out is
- Why it is coming, my server is fine i have proper internet connection ( I am on wifi not on cell phone data)
- Why it comes so many times, i am firing only two request.
It starts behaving a bad launch. I was wondering if it needs some warm up time or something like that. I would like to display the error message but not all of them probably one is fine like even if there is no data connection, displaying so many times will annoy the user.
Here is the code in my didFailWithError.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:[NSString stringWithFormat:@"Error code is %d", [error code]]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
[alertView release];
One more question how do i print the actual error message instead of this cryptic error code.
Thanks for helping me out.
[EDIT] code for establishing the connection
NSURL *getURL = [NSURL URLWithString: urlString];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
//add our HTTP headers and URL
[request setValue: @ "plain/text" forHTTPHeaderField : @"Content-Type"];
[request setHTTPMethod:@"GET"];
[request setURL : getURL];
NSURLConnection* urlConnection =
[[[NSURLConnection alloc] initWithRequest:request
delegate:delegate
startImmediately:YES] autorelease];
Yogesh
i found the answer for this, actually i have signficantLocationChange thing on, and what is happening is when the app wakes after due to the signficantLocationChange, app is suppose to make a server call to get some information, and what is happening is when the app wakes up there are situation when there is no data connection available, so all the errors are getting pilled up, and when the user opens the app he see all of that.
You may print the actual error message using the following lines:
-(void) connection:(NSURLConnection *) connection didFailWithError:(NSError *) error {
NSLog(@"localizedDescription%@", [error localizedDescription]);
}
You will have to implement the above method wherever you make your NSURLConnection
.
I am new on Stack Overflow. So, if have not followed any rule/custom while answering above question, please point out.
Get rid of the Content-Type: text/plain
request header right away. Unless you're submitting POST data along, the request doesn't have a content-type. And GET requests are not supposed to contain POST data.
精彩评论