AFHTTPClient子类中的setDownloadProgressBlock

时间:2013-07-28 08:10:35

标签: objective-c afnetworking objective-c-blocks ios6.1 afhttpclient

我创建了AFHTTPClient的子类。

可行,但progress阻止仅返回最终值(1.0)。我应该更改以获取setDownloadProgressBlock的所有计算值?

- (void)exploreVenuesCenter:(CLLocationCoordinate2D)coordinate inRadius:(int)radiusMeters success:(void (^)(NSArray *venues))success failure:(void (^)(NSError *error))failure progress:(void (^)(float progress))progress{
    NSDictionary *parameters = @{@"limit": @"10",
                                 @"client_id":kFoursquareClientID,
                                 @"client_secret":kFoursquareClientSecret,
                                 @"radius":@(radiusMeters).stringValue,
                                 @"ll":[NSString stringWithFormat:@"%g,%g",coordinate.latitude, coordinate.longitude],
                                 @"v":kFoursquareVersion};
    NSMutableURLRequest *request = [self requestWithMethod:@"GET" path:@"venues/explore" parameters:parameters];

    AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request
                                                                      success:^(AFHTTPRequestOperation *operation, id responseObject) {
                                                                          NSArray *items = responseObject[@"response"][@"groups"][0][@"items"];
                                                                          if (success)
                                                                          {
                                                                              success(items);
                                                                          }
                                                                        }
                                                                      failure:^(AFHTTPRequestOperation *operation, NSError *error) { if (failure) {
        failure(error);
        NSLog(error.localizedDescription);
    } }];
    [operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
        //
        float progressNo = ((float)totalBytesRead) / totalBytesExpectedToRead;
        if (progress) {
            progress(progressNo);
        }
    }];

    [self enqueueHTTPRequestOperation:operation];
}

0 个答案:

没有答案