views:

18

answers:

1

I have a web service used by my iPhone application.The application accesses the webservice to get authenticated.

My question is how to intimate the user when the server doesn't sends any response when it is called.

ie..The control doesn't comes to


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

A: 

When you start the login, also start an NSTimer to call a "no response" handler. Something like this:

timeout = [NSDate dateWithTimeIntervalSinceNow:10.0];
timeoutTimer = [[NSTimer alloc] initWithFireDate:timeout interval:0 target:self selector:@selector(failLogin) userInfo:nil repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:timeoutTimer forMode:NSDefaultRunLoopMode];
[loginUrlConnection start];

Now you need a failLogin method to kill the loginUrlConnection. Be sure to invalidate the timer when a response does come in:

-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *) response {
   [timeoutTimer invalidate];
   /* Handle response... */
}
John Franklin