How can I send multiple url request from a NSURLConnection delegate?

后端 未结 3 1205
天涯浪人
天涯浪人 2021-02-10 17:51

This is the logical flow for my application:

  1. At first, when the view controller has finished loading, then a NSURLConnection request can start its

3条回答
  •  一个人的身影
    2021-02-10 18:33

    - (void)viedDidLoad{
    
        [super viewDidLoad];
        [self firstRequestMethod];
    
    }
    
    - (void)firstRequestMethod{
    
        NSString *myFirstRequestURL = @"";
        NSURL *webURL = [NSURL URLWithString:myFirstRequestURL];        
    
        NSURLRequest *request = [NSURLRequest requestWithURL:webURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
        NSError *error;
        NSURLResponse *response;
        NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
        if(returnData)
        {
            NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];
            //Parse your response here.
            //Is desired response obtain call the second Request, as described above
            if (TRUE) {  //on success
                [self secondRequestMethod];
            }
    
        }
    
    
    
    }
    
    - (void)secondRequestMethod{
    
        NSString *mySecondRequestURL = @"";
        NSURL *webURL = [NSURL URLWithString:mySecondRequestURL];        
    
        NSURLRequest *request = [NSURLRequest requestWithURL:webURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
        NSError *error;
        NSURLResponse *response;
        NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
        if(returnData)
        {
            NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];
            //Parse your response here.
            //Is desired response obtain call the second Request, as described above
            if (TRUE) {  //on success
                //subsequent calls to other url, same as above
            }
    
        }
    
    
    
    }
    

    Hope this will help you understand better....

提交回复
热议问题