开发者

Web service issue in iPhone

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

M开发者_如何学编程y 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
{
}


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... */
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜