????????
??????????????APP???????漰?????????????????????????????????????????????????????????????????????????????????????????????????????????????顣??????????????????ò?????????????????????????????????????????????????????????????????????????????????????????????????????????????ú???????????????????????????????Щ???????????????????????????????????????????????????????????????ú????ò????????????????????????е????????????????????????????Щ?????????????ò????????ò??????????????????????????????????????????????????????????????????????????????£??????????????????????????????????????е??????
??????????????????????????????????????????iOS???????????У????????????????????????AFNetworking????????????м??о??????????????????????????“С??”???????????AFHTTPRequestOperation
????????????????????????????????????????????????????
???????????????????????????????????????????????????У?
????-- ???????????????????Щ
?????????????????????????????????????????????????!
NSError * error = nil;
// ???????????
NSOperationQueue * downloadOperationQueue = [[NSOperationQueue alloc]init];
//  ?漲operationQueue?У??????????е?operation?????1
downloadOperationQueue.maxConcurrentOperationCount = 1;
// ??????????????????????????????????????????????
NSMutableURLRequest * downloadRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:DOWNLOAD_URL_STRING]];
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:downloadRequest];
AFHTTPRequestOperation * downloadOperation = [[AFHTTPRequestOperation alloc]initWithRequest:downloadRequest];
unsigned long long downloadedPartFileSize = 0;
if ([[NSFileManager defaultManager] fileExistsAtPath:DOWNLOADED_PART_FILE_PATH]) {
NSDictionary * fileAttributes = [[NSFileManager defaultManager]attributesOfItemAtPath:DOWNLOADED_PART_FILE_PATH error:&error];
downloadedPartFileSize = [fileAttributes fileSize];
NSString * headerRangeFieldValue = [NSString stringWithFormat:@"bytes=%llu-"?? downloadedPartFileSize];
[downloadRequest setValue:headerRangeFieldValue forHTTPHeaderField:@"Range"];
}
downloadOperation.outputStream = [NSOutputStream outputStreamToFileAtPath:DOWNLOADED_PART_FILE_PATH append:YES];
[downloadOperation setDownloadProgressBlock:^(NSUInteger bytesRead?? long long totalBytesRead?? long long totalBytesExpectedToRead) {
NSLog(@"%lld/%lld"?? totalBytesRead + downloadedPartFileSize?? totalBytesExpectedToRead + downloadedPartFileSize);
}];
[downloadOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation?? id responseObject) {
NSLog(@"downloadOperation completion block invoked");
} failure:^(AFHTTPRequestOperation *operation?? NSError *error) {
NSLog(@"downloadOperation failure block invoked");
}];
//  ???????????????????????е???
[downloadOperationQueue addOperation:downloadOperation];
//  ????????????
[downloadOperation pause];
//  ?????????????
[downloadOperation resume];
//  ?????????????????????????????????????
[downloadOperation cancel];
[[NSFileManager defaultManager] removeItemAtPath:DOWNLOADED_PART_FILE_PATH error:&error];
//  ??????????????
[downloadOperationQueue cancelAllOperations];
//  ?????????????????ж?????????????????????...
downloadOperation.isReady
downloadOperation.isExecuting
downloadOperation.isPaused
downloadOperation.isCancelled
downloadOperation.isFinished
//  ?ж?downloadOperation????????downloadOperationQueue????
[downloadOperationQueue.operations containsObject:downloadOperation]
??????????????????AFHTTPRequestOperation????????????????????????????NSOperationQueue?С????????????????????????AFHTTPRequestOperation????????NSOperationQueue?У????γ??????????
???????????????????????????????????????????????operation???????????queue?? ?????????????????????????????????????????????operation??????????????????????????????????????????????????????operation????????????????????????????????????
?????????????
?????????????????????????????????????????????????
????????????????????????????′????????????????
??????????? 1?? ??queue??????????operation???pause???????????operation??????????????????????е???????
??????????? 2?? ???queue??????????operation???????????????????????????????????????queue????????????????
??????????? 3?? ????????????failure?????block?????????????????operation?????????????????????operation??cancel??????????????????????????“operation?????”???????????????????????????
??????????? 4?? ??????????????pause????operation???cancel????????????????operation????????queue?У????????????????pause?????????е????仯????????isCancelled??????????YES????
????......δ????????????????е??????????к??
??????????Щ?????????????????????????????????????????????????????????operation???????????±???????????????????????????ò????????????

????????ие?AFHTTPRequestOperation??NSOperationQueue??????????????????β??????????????????????????
???????????AFHTTPRequestOperation?????NSOperation??????????????????????????????????????????????????????????????????????AFNetworking???????????????????????????????????????????????????/????????????????????????????????????а????????????????NSOperation?н??е????????????????е????????????????????????????????