• 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
[Newbie]: Trouble with NSURLHandle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Newbie]: Trouble with NSURLHandle


  • Subject: [Newbie]: Trouble with NSURLHandle
  • From: Andreas Rasmussen <email@hidden>
  • Date: Sat, 2 Aug 2003 20:31:41 +0200

Hi everyone,

I'm trying to download a file via NSURLHandle - which works - and get
the NSURLHandleClient URLHandleResourceDidBeginLoading and
URLHandleResourceDidFinishLoading to be called when appropriate.
Unfortunately I can only get the first to work, and it is beginning to
bug me a little.

I've implemented my client with @interface MyClient :NSURL
<NSURLHandleClient> - se code below.

The output I get when trying to download a file, is the following:

2003-08-02 09:55:10.572 test[4157] Beginning
2003-08-02 09:55:10.682 test[4157] URLHandleResourceDidBeginLoading
2003-08-02 09:55:27.450 test[4157] status : 2, length: 437632
2003-08-02 09:55:27.455 test[4157] Done

So it successfully downloads the file, but it doesn't call any besides
URLHandleResourceDidBeginLoading. Why is this? I would also like the
-(void)URLHandle:(NSURLHandle *)sender
resourceDataDidBecomeAvailable:(NSData *)newBytes;
to be called.
I've been searching cocoa.mamasam.com and all the other documentation,
but I can't seem to find a working example.

What am I missing?

Thanks in advance.

anr

The code:

#import <Foundation/Foundation.h>


@interface MyClient :NSURL <NSURLHandleClient>
{
}

-(void)URLHandleResourceDidFinishLoading:(NSURLHandle *)sender;
-(void)URLHandle:(NSURLHandle *)sender
resourceDataDidBecomeAvailable:(NSData *)newBytes;
- (void)URLHandleResourceDidBeginLoading:(NSURLHandle *)sender;
- (void)URLHandleResourceDidCancelLoading:(NSURLHandle *)sender;
- (void)URLHandle:(NSURLHandle *)sender
resourceDidFailLoadingWithReason:(NSString *)reason;
@end

@implementation MyClient
- (void)URLHandle:(NSURLHandle *)sender
resourceDataDidBecomeAvailable:(NSData *)newBytes
{
NSLog(@"resourceDataDidBecomeAvailable");
}
- (void)URLHandleResourceDidBeginLoading:(NSURLHandle *)sender
{
NSLog(@"URLHandleResourceDidBeginLoading");
}
- (void)URLHandleResourceDidFinishLoading:(NSURLHandle *)sender
{
NSLog(@"URLHandleResourceDidFinishLoading");
}
- (void)URLHandleResourceDidCancelLoading:(NSURLHandle *)sender
{
NSLog(@"URLHandleResourceDidCancelLoading");
}
- (void)URLHandle:(NSURLHandle *)sender
resourceDidFailLoadingWithReason:(NSString *)reason
{
NSLog(@"resourceDidFailLoadingWithReason");
}
@end

int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool;

NSLog(@"Beginning");

MyClient *client;
pool = [NSAutoreleasePool new];
client = [[MyClient alloc] init];

NSURL *httpurl = [NSURL
URLWithString:@"http://download.info.apple.com/Mac_OS_X/061-
0496.20030402.2tCRd/0Z/RDClientFor10_2.dmg.bin"];
NSURLHandle *handle=[httpurl URLHandleUsingCache:YES];
[handle addClient: client];
[handle loadInBackground];

NSData *myData = [handle resourceData];
NSLog(@"status : %i, length: %i", [handle status], [myData length]);
NSLog(@"Done");

getchar();
[pool release];

return 0;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: [Newbie]: Trouble with NSURLHandle
      • From: Scott Anguish <email@hidden>
  • Prev by Date: Re: NSTextView & Leaking Memory
  • Next by Date: Re: fade-out/fade-in
  • Previous by thread: Re: fade-out/fade-in
  • Next by thread: Re: [Newbie]: Trouble with NSURLHandle
  • Index(es):
    • Date
    • Thread