【问题标题】:Getting quick response to NSUrl by sending soap message to .NET web server通过向 .NET Web 服务器发送肥皂消息来快速响应 NSUrl
【发布时间】:2011-06-04 10:57:47
【问题描述】:

我是网络服务的新手。我需要从 .NET Web 服务器获取信息。为此,我使用以下代码:

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    [webData setLength: 0];

}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [webData appendData:data];
    if (data) {
        NSLog(@" bcxbm,xcm,xcmcmx,b data consist %@",data);
    }
    else {
        NSLog(@"not exist");
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:@"<Alert message>" delegate:self cancelButtonTitle:@"Retry" otherButtonTitles:@"Cancel", nil];
        [alert show];
        [alert release];
    }

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

    NSLog(@"ERROR with theConenction");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"DONE. Received Bytes: %d", [webData length]);

我能够获取信息,但我需要对其进行验证。如果没有连接,我需要触发Alertview。为此,我有代码:

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {
        [webData appendData:data];
        if (data) {
            NSLog(@" bcxbm,xcm,xcmcmx,b data consist %@",data);
        }
        else {
            NSLog(@"not exist");
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView" message:@"<Alert message>" delegate:self cancelButtonTitle:@"Retry" otherButtonTitles:@"Cancel", nil];
            [alert show];
            [alert release];
        }

    }

我通过删除连接来检查。但它不会触发任何警报。一段时间后,它会在控制台中显示Error in connection。但这需要很多时间。除了这个还有其他可能吗?没有连接时如何显示警报?

谁能帮帮我?

【问题讨论】:

    标签: iphone


    【解决方案1】:

    connection didFailWithError: 将在无法建立连接时调用。如果正在调用连接didReceiveData:,则意味着您正在从Web 服务接收某种数据。

    当您删除连接时,您的代码会尝试连接到 Web 服务并在预定义的时间间隔后超时,即调用连接 didFailWithError: 时。在发生超时之前尝试连接需要时间。

    您甚至可以在使用 Apple 的 Reachability example 建立连接之前检查互联网连接。你可以从this link看到如何使用它

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-29
    • 2017-08-20
    • 2019-09-16
    • 2011-04-29
    • 1970-01-01
    • 2011-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多