views:

595

answers:

2
- (IBAction)startDownloadingURL:(id)sender
{
    // create the request
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/index.html"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

    // create the connection with the request
    // and start loading the data
    NSURLDownload  *theDownload=[[NSURLDownload alloc] initWithRequest:theRequest delegate:self];

    if (!theDownload) {
        // inform the user that the download could not be made
    }
}

when i run the simulator , i got an error:

NSURLDownload undeclared ,first use in this fuction.

where can i import the library of NSURLDownload.

+2  A: 

NSURLDownload not on iPhone see the note:

iPhone OS Note: The NSURLDownload class is not available in iPhone OS as downloading directly to the file system is discouraged. Use the NSURLConnection class instead. See “Using NSURLConnection” for more information.

Have a look at Apple's documentation about URL loading system and NSURLDownload.

stefanB
I assume by simulator you mean iPhone simulator so you are compiling this for iPhone not desktop.
stefanB
A: 

If you've just looking to grab the contents of the page:

NSData *pageContents = [NSData dataWithContentsOfURL: [URLWithString:@"http://www.apple.com"]];
christo16