AFNetworking怎么设置上传进度条?

查了一圈,查到了setuploadprogress 这个方法,但是不知道怎么用。
补一下代码吧

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:urlStr parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileData:imgData name:@"pic" fileName:fileName mimeType:@"image/jpeg"];
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"success:%@",responseObject);
        NSInteger result = [[responseObject objectForKey:@"result"] integerValue];
        if (result == 1) {
            successBlock(responseObject);
        }else{
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:@"出错了" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
            [alertView show];
        }

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:[error localizedDescription] delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        [alertView show];
        failureBlock(error);
    }];
阅读 9.4k
2 个回答
- (void)setUploadProgressBlock:(void (^)(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))block;

在block里 totalBytesWritten / totalBytesExpectedToWrite

AFHTTPRequestOperation *op = xxx;
[self.uploadProgressView setProgressWithUploadProgressOfOperation:op animated:YES];
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题