Downloading Progress

Syphor

Registered
Hi I'd like to make a very simple downloading program. Here is what I have and I want my progress bar to indicate where how much of the file the program has downloaded.

Anway here is my code:

Code:
/* Controller.h */

#import <Cocoa/Cocoa.h>

@interface Controller : NSObject
{
    IBOutlet id downloadProgress;
    
    NSURL *myURL;
    NSData *urlContents;
}
- (IBAction)download:(id)sender;

- (void)Bam;
@end

Code:
/* Controller.m */

#import "Controller.h"

@implementation Controller

- (IBAction)download:(id)sender
{
    myURL = [NSURL URLWithString:@"http://www.apple.com/"];
    urlContents = [myURL resourceDataUsingCache:YES];
    
    [downloadProgress setUsesThreadedAnimation:YES];
    
    [NSThread detachNewThreadSelector: @selector(Bam) toTarget: self withObject:downloadProgress];

}

- (void)Bam
{
    NSAutoreleasePool *apool=[[NSAutoreleasePool alloc] init];
    
    NS_DURING
    
    [urlContents writeToFile:[@"~/Documents/applewebsite.html" stringByExpandingTildeInPath] atomically:YES];
    [downloadProgress displayIfNeeded];
    
    NS_HANDLER
         NS_ENDHANDLER
    
    [apool release];
}
@end
 
Back
Top