How can we handle multiple NSURLConnection in iPhone Xcode?

后端 未结 3 857
青春惊慌失措
青春惊慌失措 2020-12-30 17:43

I am developing one small app in which i have multiple NSURLConnection.I have created that NSURL Connection but i don\'t know how to handle it.My code is like below.

相关标签:
3条回答
  • 2020-12-30 18:37

    you might want to take a look at AFNetworking for an easier and tidier way of doing network requests.

    0 讨论(0)
  • 2020-12-30 18:37

    Implement NSURLConnection delegate methods and rest will be handle by itself

    0 讨论(0)
  • 2020-12-30 18:38

    Declare conn,conn1,conn2,conn3 in .h file. Then do the following. in loadTrafficAndEvent:

    conn1 = [[NSURLConnection alloc] initWithRequest:request1 delegate:self];
    

    in connectionDidFinishDownloading: method,

    - (void)connectionDidFinishDownloading:(NSURLConnection *)connection destinationURL:(NSURL *)destinationURL{
    if(connection==conn){
    conn1 = [[NSURLConnection alloc] initWithRequest:request1 delegate:self];
    }
    else if(connection==conn1){
    conn2 = [[NSURLConnection alloc] initWithRequest:request2 delegate:self];
    }
    else if(connection==conn2){
    conn3 = [[NSURLConnection alloc] initWithRequest:request3 delegate:self];
    }
    
    }
    

    Do the operations inside each if else condition, and no need to allocate and initialize all NSURLConnection in loadTrafficAndEvent: The download will occur one after other.

    0 讨论(0)
提交回复
热议问题