Last active
December 11, 2015 05:29
-
-
Save saturngod/4552749 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSDictionary* headers = [(NSHTTPURLResponse *)response allHeaderFields]; | |
if ([headers objectForKey:@"Accept-Ranges"]) { | |
_allowResume = YES; | |
} | |
else | |
{ | |
_allowResume = NO; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)resume | |
{ | |
//add range for resume but some of the server didn't support resume | |
NSString *range = @"bytes="; | |
range = [range stringByAppendingString:[[NSNumber numberWithInt:self.receiveBytes] stringValue]]; | |
range = [range stringByAppendingString:@"-"]; | |
NSURL* fileURL = self.request.URL.absoluteURL; | |
self.resumeProgress = YES;//add trigger for except exceptedBytes | |
self.request = [[NSMutableURLRequest alloc] initWithURL:fileURL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:self.tmpTimeout]; | |
[self.request setValue:range forHTTPHeaderField:@"Range"]; | |
self.connection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self startImmediately:YES]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SGdownloader *downloader = [[SGdownloader alloc] initWithURL:[NSURL URLWithString:@"http://myfile.com/file.jpg"] timeout:60]; | |
[downloader startWithDownloading:(float progress,NSInteger percentage) { | |
//progress for progress bar | |
//percentage for download percentage | |
} onFinished:(NSData* fileData,NSString* fileName){ | |
//use NSData to write a file or image | |
}onFail (NSError* error){ | |
//on fail | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment