URL Loading System Programming Guide - Apple Developer
URL Loading System Programming Guide - Apple Developer
URL Loading System Programming Guide - Apple Developer
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Using NS<strong>URL</strong>Download<br />
Downloading to a Predetermined Destination<br />
NS<strong>URL</strong>Request *theRequest = [NS<strong>URL</strong>Request requestWith<strong>URL</strong>:[NS<strong>URL</strong><br />
<strong>URL</strong>WithString:@"http://www.apple.com"]<br />
cachePolicy:NS<strong>URL</strong>RequestUseProtocolCachePolicy<br />
timeoutInterval:60.0];<br />
// Create the connection with the request and start loading the data.<br />
NS<strong>URL</strong>Download<br />
*theDownload = [[NS<strong>URL</strong>Download alloc] initWithRequest:theRequest<br />
delegate:self];<br />
if (theDownload) {<br />
// Set the destination file.<br />
[theDownload setDestination:@"/tmp" allowOverwrite:YES];<br />
} else {<br />
// inform the user that the download failed.<br />
}<br />
}<br />
- (void)download:(NS<strong>URL</strong>Download *)download didFailWithError:(NSError *)error<br />
{<br />
// Dispose of any references to the download object<br />
// that your app might keep.<br />
...<br />
// Inform the user.<br />
NSLog(@"Download failed! Error - %@ %@",<br />
[error localizedDescription],<br />
[[error userInfo] objectForKey:NS<strong>URL</strong>ErrorFailing<strong>URL</strong>StringErrorKey]);<br />
}<br />
- (void)downloadDidFinish:(NS<strong>URL</strong>Download *)download<br />
{<br />
// Dispose of any references to the download object<br />
// that your app might keep.<br />
...<br />
2013-10-22 | Copyright © 2003, 2013 <strong>Apple</strong> Inc. All Rights Reserved.<br />
41