1

在我的应用程序中,我遇到了多个 Web 服务同时被占用的场景。我想知道检查特定 ASIFormDataRequest 是否仍在进行中的最佳方法。

4

2 回答 2

7

您可以像 yourRequest.tag 一样将标签设置为 ASIHttpRequest 并使用以下委托方法。如果完全成功完成,它将进入 requestFinished,如果出现问题,它将进入 requestFailed。

- (void)requestFinished:(ASIHTTPRequest *)request
{
   // Use when fetching text data
   NSString *responseString = [request responseString];
}

- (void)requestFailed:(ASIHTTPRequest *)request
{
   NSError *error = [request error];
}
于 2012-07-30T10:11:16.597 回答
3

检查以下代码它可能对您有所帮助

        if (!networkQueue) 
        {
            networkQueue = [[ASINetworkQueue alloc] init];  
        }
        [networkQueue reset];
        [networkQueue setRequestDidFinishSelector:@selector(requestDone:)];
        [networkQueue setRequestDidFailSelector:@selector(requestWentWrong:)];
        [networkQueue setShowAccurateProgress:TRUE];
        [networkQueue setDelegate:self];
        ASIHTTPRequest *requestqueue;
         requestqueue = [[[ASIHTTPRequest alloc] initWithURL:[NSURL URLWithString:str_imageurl]] autorelease];
         [requestqueue setDownloadDestinationPath:[str_downloadpath stringByAppendingPathComponent:str_imgname]];
       NSMutableDictionary *dictinfo=[[NSMutableDictionary alloc]init];
       [dictinfo setValue:str_settingvalue forKey:@"SettingValue"];
       [requestqueue setUserInfo:dictinfo];
       [networkQueue addOperation:requestqueue];
      [networkQueue go];

关于代表方法

    //queue responder....
   -(void)requestDone:(ASIHTTPRequest *)request
     {
         NSLog(@"%@",[request userInfo]);
         if ([[[request userInfo]valueForKey:@"SettingValue"]isEqualToString:kAppSplashScreenDOWNLOADURL]) 
         {
           //FORM DATA REQEUST FOR PARTICULAR REQUEST HAS BEEN SUCCESS FULL
         }
     } 
    -(void)requestWentWrong:(ASIHTTPRequest *)request
    {
        NSLog(@"%@",[request userInfo]);
         if ([[[request userInfo]valueForKey:@"SettingValue"]isEqualToString:kAppSplashScreenDOWNLOAD]) 
         {
           //FORM DATA REQEUST FOR PARTICULAR REQUEST HAS BEEN FAIL
         }

    }

问候尼基尔

于 2012-07-31T12:25:06.357 回答