0

我创建了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];
}
4

0 回答 0