代码之家  ›  专栏  ›  技术社区  ›  Tim Büthe

为什么在使用ASIHTTPRequest时活动指示器永远不会结束?

  •  0
  • Tim Büthe  · 技术社区  · 14 年前

    我使用ASIHTTPRequest在我的iPhone应用程序中执行http请求。asihttprequest附带了这样一个功能:在发出请求时启动活动指示器,在完成请求时停止活动指示器。问题是,一旦我启动了一个请求,指示灯就不会停止并一直旋转,直到我的应用程序运行。

    这是我的代码,一个小的实用程序方法,它可以从web同步获取一些内容(因为它是在另一个线程中启动的):

    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL: [NSURL URLWithString: url]];
    [request startSynchronous];
    
    NSError *error = [request error];
    NSString *response = nil;
    
    if (error) {
        NSLog(@"error %@", error);
        return nil;
    }
    
    int statusCode = [request responseStatusCode];
    response = [NSString stringWithString: [request responseString]];
    NSLog(@"status code: %d response: %@", statusCode, response);
    
    if (statusCode != 200) {
        return nil;
    }
    
    return response;
    

    上面的代码工作得很好,我将给定URL的内容作为NSString,只有指示符继续旋转。我的问题是:为什么指示器从不停止,如何修复它?我需要在这里释放一些资源吗?

    2 回复  |  直到 14 年前
        1
  •  3
  •   pokeb    14 年前

    这是最近在ASIHTTPRequest的开发版本中修复的一个错误:

    http://github.com/pokeb/asi-http-request/commit/35ea592084145b3332861344f36b52dbcaafa351

    (它只影响在辅助线程上启动的同步请求)

        2
  •  0
  •   Ben Scheirman    14 年前