• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problems getting NSURLConnection to work
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Problems getting NSURLConnection to work
      • From: Nir Soffer <email@hidden>
References: 
 >Problems getting NSURLConnection to work (From: Matthew Delves <email@hidden>)

  • Prev by Date: Re: wired things about NSApp Modal
  • Next by Date: Re: help with closing file handle
  • Previous by thread: Re: Problems getting NSURLConnection to work
  • Next by thread: Re: Problems getting NSURLConnection to work
  • Index(es):
    • Date
    • Thread