AFN2.0上传进度条设置
来源:互联网 发布:淘宝店服装细节模板 编辑:程序博客网 时间:2024/05/21 10:28
在使用AFN上传图片的时候如果是3.0版本可以直接获取到当前上传的进度。
self.progressView1.progress = 1.0 * uploadProgress.completedUnitCount/ uploadProgress.totalUnitCount;
如果使用2.0只能看到成功或者失败尝试好的方法进行操作
// 1. Create `AFHTTPRequestSerializer` which will create your request. AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer]; // 2. Create an `NSMutableURLRequest`. NSMutableURLRequest *request = [serializer multipartFormRequestWithMethod:@"POST" URLString:@"http://116.255.251.220:680/api/Files/PostFile" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithFileData:imageData name:@"attachment" fileName:@"myimage.jpg" mimeType:@"image/jpeg"]; }]; // 3. Create and use `AFHTTPRequestOperationManager` to create an `AFHTTPRequestOperation` from the `NSMutableURLRequest` that we just created. AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; AFHTTPRequestOperation *operation = [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) { [self.progressView1 hidePopUpViewAnimated:YES]; NSLog(@"Success %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { [self.progressView1 hidePopUpViewAnimated:YES]; NSLog(@"Failure %@", error.description); }]; // 4. Set the progress block of the operation. [operation setUploadProgressBlock:^(NSUInteger __unused bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) { [self.progressView1 showPopUpViewAnimated:YES]; NSLog(@"Wrote %lld/%lld", totalBytesWritten, totalBytesExpectedToWrite); dispatch_async(dispatch_get_main_queue(), ^{ self.progressView1.progress = 1.0 * totalBytesWritten/ totalBytesExpectedToWrite; }); }]; // 5. Begin! [operation start];
上述就是使用AFN2.0上传时获取当前上传进度和上传内容大小。
0 0
- AFN2.0上传进度条设置
- AFN2.0的使用
- AFN2
- iOS AFN2.0请求封装使用
- afn2.0同步和异步 及读取json格式
- Struts2.0实现上传文件进度条
- Struts2.0实现上传文件进度条
- 进度条设置
- 带进度条文件上传
- 上传进度条代码
- JS实现上传进度条
- ajax 文件上传进度条
- struts2上传实时进度条
- 上传时显示进度条
- JS实现上传进度条
- ajax 上传进度条
- struts2上传文件进度条
- ftp支持进度条上传
- 多态
- Redis 数据类型要点
- 无损压缩算法发展
- Android Material Design之TextInputLayout、TextInputEditText解析
- jvm 中生代cmcc的gc和fullgc
- AFN2.0上传进度条设置
- ubuntu C 语言 段错误 (核心已转储)
- WebView加载h5,h5更新了,app里一直没更新
- 字典树(1)--hdu5269(字典树基本应用)
- 非J2EE部署解决方案
- Ansible入门简介
- [leetcode] 412. Fizz Buzz 解题报告
- android短信验证码自动填充
- ld:framework not found Pods__ clang: error: linker command faild with code 1