You keep pointers to both connections in the delegate, and compare these to the connection
parameter in connection:didReceiveData:
and connectiondidFinishLoading:
For example:
@interface Foo : NSObject {
NSURLConnection *connection1;
NSURLConnection *connection2;
}
and
connection1 = [NSURLConnection connectionWithRequest:request1 delegate:self];
connection2 = [NSURLConnection connectionWithRequest:request2 delegate:self];
and
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
if(connection == connection1) {
// Connection 1
} else if(connection == connection2) {
// Connection 2
}
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
if(connection == connection1) {
// Connection 1
} else if(connection == connection2) {
// Connection 2
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…