這是我的代碼,它嘗試使用NSURLDownload下載網頁。但它不起作用,它是一個命令行程序。使用NSURLDownload下載網頁
- (void)startDownloadingURL
{
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/index.html"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// Create the download with the request and start loading the data.
NSURLDownload *theDownload = [[NSURLDownload alloc] initWithRequest:theRequest delegate:self];
if (theDownload) {
// Set the destination file.
[theDownload setDestination:@"/saleh" allowOverwrite:YES];
} else {
// inform the user that the download failed.
NSLog(@"download has failed!");
}
}
對此不起作用?它會打印「下載失敗!」嗎?您是否實施了任何[NSURLDownloadDelegate](http://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSURLDownloadDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/NSURLDownloadDelegate)方法,例如' downloadDidFinish:'或'download:didFailWithError:'? –
它不會給我任何錯誤!我已經實施了代表,但他們似乎不起作用!我不知道是什麼問題。 –