Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-16-2009, 03:48 AM   #1 (permalink)
blu
Registered Member
 
Join Date: Jan 2009
Posts: 16
blu is on a distinguished road
Default Error from NSURLDownload (cannot open file)

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");
}
blu is offline   Reply With Quote
Old 01-16-2009, 11:44 AM   #2 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 3
oxrxb is on a distinguished road
Default

NSURLDownload is not available for the iPhone OS. Use URLConnection instead.

From the iPhone reference library:
Quote:
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.
oxrxb is offline   Reply With Quote
Old 01-18-2009, 10:36 PM   #3 (permalink)
blu
Registered Member
 
Join Date: Jan 2009
Posts: 16
blu is on a distinguished road
Default

Thank you,It's work.

Last edited by blu; 01-20-2009 at 03:12 AM.
blu is offline   Reply With Quote
Reply

Bookmarks

Tags
download, nsurldownload

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 414
17 members and 397 guests
7twenty7, Alex-alex, Apptronics RBC, baja_yu, dre, FrankWeller, gwelmarten, ipodphone, jeroenkeij, jleannex55, matador1978, n00b, pbart, reficul, Retouchable, Sami Gh, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:19 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0