I try to download file from url but it return Error
"Download failed! Error - Cannot open file http://www.google.com/index.html"
I don't know why? anyone can help me?
Thanks in advance
Here's my code
Code:
- (void)startDownloadingURL:sender {
//create request
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/index.html"]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
//create connection with the request
//and start loading the data
NSURLDownload *theDownload = [[NSURLDownload alloc] initWithRequest:theRequest delegate:self];
if (!theDownload) {
//inform user that the download could not be made
NSLog(@"Can not load this file");
}
}
- (void)download:(NSURLDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename
{
NSString *destinationFilename;
NSString *homeDirectory=NSHomeDirectory();
destinationFilename = [[homeDirectory stringByAppendingPathComponent:@"Desktop"]
stringByAppendingPathComponent:filename];
[download setDestination:destinationFilename allowOverwrite:YES];
}
- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
{
//release the connection
[download release];
//inform the user
NSLog(@"Download failed! Error - %@ %@",[error localizedDescription],[[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
}
- (void)downloadDidFinish:(NSURLDownload *)download
{
//release the connection
[download release];
//do something with data
NSLog(@"%@",@"downloadDidFinish");
}