Re: Problems getting NSURLConnection to work
Re: Problems getting NSURLConnection to work
- Subject: Re: Problems getting NSURLConnection to work
- From: Nir Soffer <email@hidden>
- Date: Sat, 9 Feb 2008 15:14:51 +0200
On Feb 9, 2008, at 07:19, Matthew Delves wrote:
I've setup a class as a delegate for NSURLConnection, though when I
create the NSURLConnection and provide it a delegate (self), the
delegate methods don't get called. I know they don't get called as
I've put in NSLog() statements and these statements don't get
displayed.
Is there something I'm missing?
Follows is the code from the class implementation file:
- (id) initWithUrl:(NSURL *)aUrl
{
/*
NSURLConnection why won't you work?
I follow your documentation, why won't you work?
I remove garbage collection, why won't you work?
I change the thread you run on, why won't you work?
On which thread do you run this? It works fine on the main thread.
NSURLConnection why won't you work?
*/
url = [aUrl copy]; // copy the url
Why copy the url?
[url retain];
And then retain it!?
NSLog(@"%@", url);
Can you access this url with a browser?
responseString = nil;
responseCode = 0.0;
responseCode is a float?!
document = nil;
urlConnection = nil;
urlRequest = nil;
urlResponse = nil;
urlData = nil;
urlRequest = [[NSMutableURLRequest alloc] initWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60.0];
[urlRequest retain];
Why retain an object created with alloc?
[urlRequest setMainDocumentURL:url];
[urlRequest setURL:url];
Why do you set the url again?
if([NSURLConnection canHandleRequest:urlRequest])
urlConnection = [NSURLConnection connectionWithRequest:urlRequest
delegate:self];
if(urlConnection) {
[urlConnection retain];
If you want to retain the object, why not create it with –
initWithRequest:delegate:?
urlData = [[NSMutableData alloc] init];
[urlConnection start];
start? NSURLConnection does not respond to this. The connection
starts when you create it.
I guess that at this point an exception is raised and your
initializer fails. This is why you don't get any notifications.
Best Regards,
Nir Soffer
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden