0
votes

In my app,I used the AFHTTPRequestOperationManager for API integration and its working. I need to show the progress for data download and i checked with setCompletionBlockWithSuccess callback but it isn't called. How to find the data download in AFHTTPRequestOperationManager.

Kindly help me.


AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager manager] initWithBaseURL:[NSURL URLWithString:@""]];
[manager.requestSerializer setValue:SourceType forHTTPHeaderField:@"Source"];
[manager.requestSerializer setValue:sig forHTTPHeaderField:@"Sig"];
[manager GET:mtdName parameters:params success:^(AFHTTPRequestOperation *operation, id responseDict)
     {}
         failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {}];

2

2 Answers

0
votes

I find in : http://cocoadocs.org/docsets/AFNetworking/2.2.3/

    Creating a Download Task
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration     defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc]     initWithSessionConfiguration:configuration];

NSURL *URL = [NSURL URLWithString:@"http://example.com/download.zip"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];

NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
NSLog(@"File downloaded to: %@", filePath);
}];
[downloadTask resume];
0
votes

Use This:

    AFHTTPRequestOperation *operation;
operation = 
[manager HTTPRequestOperationWithRequest:[[AFJSONRequestSerializer serializer] requestWithMethod:method URLString:url parameters:info] success:^(AFHTTPRequestOperation *operation, id responseObject) {
}];


[operation setDownloadProgressBlock:^(NSUInteger bytesRead, NSInteger totalBytesRead, NSInteger totalBytesExpectedToRead) {
    //do something here.
}];

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.securityPolicy.allowInvalidCertificates = YES ;//if use https
[manager.operationQueue addOperation:operation];