3
- (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 function.

Where can I import the library of NSURLDownload.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
marshluca
  • 921
  • 2
  • 9
  • 9

2 Answers2

10

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
  • 77,323
  • 27
  • 116
  • 141
  • I assume by simulator you mean iPhone simulator so you are compiling this for iPhone not desktop. – stefanB Mar 23 '10 at 02:36
2

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

NSData *pageContents = [NSData dataWithContentsOfURL: [NSURL URLWithString:@"http://www.apple.com"]];
christo16
  • 4,843
  • 5
  • 42
  • 53
  • Hi @christo16, would you mind see my question here? I just wonder whether there is a better technique : http://stackoverflow.com/questions/7950384/why-nsdata-datawithcontentsofurl-sometimes-return-null-value – swdev Oct 31 '11 at 05:56
  • 1
    @christo16 You're missing `NSURL` before `URLWithString`, that portion should be: `[NSURL URLWithString:@"http://www.apple.com"]` – Jonathan Head Dec 20 '14 at 20:27