PDA

View Full Version : NSURLHandle not working


Unregistered
2002.07.18, 12:28 PM
----in header file

NSURL *site;
NSURLHandle *theFile;

---in header file

-(void)awakeFromNib{
site=[[NSURL alloc]initWithString:@"http://www.macosrumors.com/images/logo.gif"];
theFile=[site URLHandleUsingCache:NO];

[theFile addClient:self];
[theFile beginLoadInBackground];}


- (void)URLHandle:(NSURLHandle *)sender resourceDidFailLoadingWithReason:(NSString *)reason{NSLog(@"%@",reason);}

- (void)URLHandleResourceDidFinishLoading:(NSURLHand le *)sender{NSLog(@" %f bytes",[[sender resourceData]length]);}

- (void)URLHandleResourceDidBeginLoading:(NSURLHandl e *)sender{NSLog(@"started");}

ok, where to start.......
I have a URL, that i use to make a urlhandle, that i tell to load. I also add self as a client so i will be notified when something happens.

Now for the weird stuff.
1)If i use "theFile=[[NSURLHandle alloc]initWithURL:site cached:NO];" then i get this in the Run pane of pb
"
*** -beginLoadInBackground cannot be sent to an abstract object of class NSURLHandle: Create a concrete instance!"
so i set file using "theFile=[site URLHandleUsingCache:NO];"

2)beginLoadInBackground does nothing, i have to have it load
calling "[theFile resourceData];" now it will load but only
"URLHandleResourceDidFinishLoading:"
is called, and when i check for the data length it returns zero.

im just trying to get a NSURLHandle working correctly, but im not sure whats wrong?:confused:

Griggs
2002.07.18, 12:53 PM
Hi.
I edited your post to turn off smilies, as you may have noticed some bits of your code were being parsed as smilies, kind of disturbing the flow. Since you are not registered and cannot edit your post I took the liberty of doing so.

When posting code it may be a good idea to select the "Disable Smilies in This Post" checkbox, otherwise if your code includes :( or any other combo it will be replaced with the smily image.

Unregistered
2002.07.18, 12:55 PM
thanks griggs

OneSadCookie
2002.07.18, 03:43 PM
1) is expected; the documentation hints at this. You're solving the problem in the right way.

2) beginLoadInBackground is a notification sent to the URLHandle, not a command to it. You want to call loadInBackground instead.

resourceData is a synchronous method, so it won't call you back with progress. loadInBackground should call you back periodically.

Unregistered
2002.07.18, 06:27 PM
gotcha, the NSURLClient methods are responding now.

- (void)URLHandleResourceDidFinishLoading:(NSURLHand le *)sender{
NSLog(@"%f",[[sender resourceData]length]);}

but when i check the length of the data, it is at 0.

I tried these URLs

http://www.idevgames.com/img/gui/eye.gif
http://www.macosrumors.com/images/logo.gif

dont get me wrong though, i would just like to load any data at a url, not just images. I am connected to the internet when i do this, but the above is all the code i am running, i am pretty sure i dont need to get a NSSocket, NSConnection going, or do i?

Pazolli
2002.07.19, 12:56 PM
I have a nice little open source example of dealing with NSURLHandle. Perhaps you'd like to check it out:

http://64.246.17.165/downloads/srccocoa/fcisource.sit

It is licensed under the GNU General Public License but I give you permission to do whatever you want with it, no strings attached. (I can do this because it's completely my code so I can waive the GPL if I want to).

All I ask is that you please consider releasing the code to some of your future work. If we share our work, we become more powerful and can produce something more impressive with less effort.

Cheers.

Unregistered
2002.07.19, 09:23 PM
yeah, no problem, i can post my 2d game code when i am done with it.(if i ever get done)
id like to help out alot, but i think that everybody is ahead of me, i just started about 3 months ago. thanks