Re: Use multiple NSURLConnection
Re: Use multiple NSURLConnection
- Subject: Re: Use multiple NSURLConnection
- From: Andrei Tchijov <email@hidden>
- Date: Wed, 3 Aug 2005 09:49:32 -0400
Two possible solutions:
1) allocate individual "receivedData" for each connection and
then store it in such a way that you can find "proper" instance of
"receivedData" based on connection object. You can use
NSMutableDictionary to store these "recevedData" objects and use
connection object itself as a key.
2) define "proxy" delegate class which will store enough of a
context to distinguish between different connections and use objects
of this class as a delegates. Nature of "context" will depend on
what you are planing to do with received data, but at very least it
can hold "recevedData" object to be used with given connection.
On Aug 3, 2005, at 09:30, email@hidden wrote:
I need to use more than one NSURLConnection, but How can I do it in
the same code?
Every NSURLConnection responds to - (void)connection:
(NSURLConnection *)connection didReceiveData:(NSData *)dat
- (void) startDownloadingURL
{
NSURLRequest *theRequest=[NSURLRequest requestWithURL:
[NSURL URLWithString:authString]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
theConnection=[[NSURLConnection alloc]
initWithRequest:theRequest delegate:self];
if (theConnection) receivedData=[[NSMutableData data] retain];
else NSLog(@"Problems downloading data");
}
- (void)connection:(NSURLConnection *)connection didFailWithError:
(NSError *)error
{
[connection release];
[receivedData release];
NSLog(@"Connection failed! Error - %@ %@", [error
localizedDescription], [[error userInfo]
objectForKey:NSErrorFailingURLStringKey]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
}
- (void)connection:(NSURLConnection *)connection didReceiveData:
(NSData *)data
{
[receivedData appendData:data];
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden