如何获得AFHTTPRequest的进度?我尝试在网上搜索。
我在用:

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSDictionary *params = @{@"gameId" : datas[0], @"p1": datas[1], @"p2":datas[2], @"turn":datas[3] };
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager POST:@"http://localhost/thepath/isprivate/thefile.php"
       parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    }];

有没有可以用来访问AFNetworking 2.0 HTTP POST进度的属性或方法?

最佳答案

您可以使用以下方法

- (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request
                                         fromData:(NSData *)bodyData
                                         progress:(NSProgress * __autoreleasing *)progress
                                completionHandler:(void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler

AFHTTPSessionManager类。

更新:

通常,您会更喜欢使用KVO来获取值。因此,应使用如下所示的内容:
static void * kDGProgressChanged = &kDGProgressChanged;

...

[progress addObserver:self
           forKeyPath:@"fractionCompleted"
              options:NSKeyValueObservingOptionNew
              context:kDGProgressChanged];

...

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(__unused NSDictionary *)change
                       context:(void *)context
{
    if (kDGProgressChanged == context) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [self updateProgressInfo];
        });
    }
}

关于ios - AFNetworking 2.0 HTTP POST进度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21951700/

10-14 20:42