简体   繁体   English

iPhone中的Web服务问题

[英]Web service issue in iPhone

I have a web service used by my iPhone application.The application accesses the webservice to get authenticated. 我的iPhone应用程序使用了一个Web服务。该应用程序访问Web服务以进行身份​​验证。

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
{
}

When you start the login, also start an NSTimer to call a "no response" handler. 开始登录时,还要启动NSTimer来调用“无响应”处理程序。 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 . 现在,您需要一个failLogin方法来杀死loginUrlConnection Be sure to invalidate the timer when a response does come in: 请确保在收到响应时使计时器无效:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM