???????????????????????Щ??
???????????? ???????[ 2015/9/10 11:02:58 ] ??????????????????
????????
??????????????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?н??е????????????????е????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11