Question

When I open the app from background I need to hit server to get some data. When I'm doing so I am getting an alert as follows:

"Request timed out" (nserror's localised description)

I'm on wifi and my internet as well as my server are fine.

This is not happening every time but happening frequently. Here is my code:

NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:myUrlString]];     
NSURLConnection *conn=[[NSURLConnection alloc]initWithRequest:request delegate:self]; //sending request for data self.dataConnection=conn; [conn release];


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

UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Error" message:@"Network Exception" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
[alert show]; 
[alert release]; 
}

What am I doing wrong and how can I fix this?


NSURLRequest *lRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:link] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0]; 

even i've used the above line instead of

NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:myUrlString]]; 

but found nothing different . Still my request is getting timed out. Why is it getting timed out even when my server aswell as wifi (internet) are fine.?? Thanks in Advance....

Was it helpful?

Solution

NSURLRequest *lRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:link] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];

From here you can get the guidance...NSURLConnection timeout?

OTHER TIPS

If you're confident of your server-side then it may be not a software, but a hardware-specific issue. I have this issue very often with my iPod5 connected to home wifi, despite all other devices connected to the same wifi are fine. Today I have tested connection to my server on problem device via another wifi - timeout errors were disappeared. Weird. Who you gonna call?..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top