【问题标题】:Web service issue in iPhoneiPhone 中的 Web 服务问题
【发布时间】:2010-09-16 13:38:50
【问题描述】:

我的 iPhone 应用程序使用了一个 Web 服务。该应用程序访问该 Web 服务以进行身份​​验证。

我的问题是当服务器在被调用时没有发送任何响应时,如何通知用户

ie..控制不来

-(无效)连接:(NSURLConnection *)连接didReceiveResponse:(NSURLResponse *)响应 { }

【问题讨论】:

  • webservice 使用哪种身份验证方法? (基本、摘要、Kerberos、...?)

标签: iphone objective-c web-services


【解决方案1】:

当您开始登录时,还要启动NSTimer 来调用“无响应”处理程序。像这样的:

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];

现在你需要一个failLogin 方法来杀死loginUrlConnection。确保在收到响应时使计时器无效:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-12
    • 1970-01-01
    • 1970-01-01
    • 2012-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多