Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios7 取消AFHttpRequestOperation_Ios7_Afhttprequestoperation - Fatal编程技术网

Ios7 取消AFHttpRequestOperation

Ios7 取消AFHttpRequestOperation,ios7,afhttprequestoperation,Ios7,Afhttprequestoperation,我正在使用AFHttpRequestOperation下载图像,我想单击按钮取消此操作。我如何执行此操作 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:strImagePath]]; self.managerDownloadActualImage = [AFHTTPRequestOperationManager manager]; self.managerDownloadActualImage.

我正在使用AFHttpRequestOperation下载图像,我想单击按钮取消此操作。我如何执行此操作

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:strImagePath]];
self.managerDownloadActualImage = [AFHTTPRequestOperationManager manager];
self.managerDownloadActualImage.responseSerializer = [AFHTTPResponseSerializer serializer];
self.operationImageDownload = [self.managerDownloadActualImage HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"Download succeeded.");
    chatData.isDownloaded = [NSNumber numberWithBool:YES];
    chatData.isThumbDownloaded = [NSNumber numberWithBool:YES];
    NSData *responseData = (NSData *)responseObject;
    chatData.actual_path = [NSString stringWithFormat:@"%@",[self saveImageInDocumemntDirectoryWithImageData:responseData]];
    [self saveData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Download failed with error: %@", error);
}];

[self.operationImageDownload setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
    NSLog(@"Bytes read: %lu", (unsigned long)bytesRead);
    NSLog(@"Total bytes read %lld", totalBytesRead);
    NSLog(@"Total progress: %Lf", (long double)totalBytesRead / totalBytesExpectedToRead);

    int currentPercentage = ((long double)totalBytesRead / totalBytesExpectedToRead) * 100;
    if (currentPercentage <= 100) {
        self.customProgressView.percent = currentPercentage;
        [self.customProgressView setNeedsDisplay];
    }
    else {
        [self.customProgressView removeFromSuperview];
    }
}];

NSLog(@"Starting download.");
[self.operationImageDownload start];
但这并没有停止下载过程

[self.managerDownloadActualImage.operationQueue cancelAllOperations];