查了一圈,查到了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);
}];
在block里 totalBytesWritten / totalBytesExpectedToWrite