- (IBAction)startDownloadingURL:(id)sender
{
// create the request
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/index.html"] cachePolicy:NSURLRequ开发者_如何转开发estUseProtocolCachePolicy 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.
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.
If you've just looking to grab the contents of the page:
NSData *pageContents = [NSData dataWithContentsOfURL: [NSURL URLWithString:@"http://www.apple.com"]];
精彩评论