Eve*_*Eve 6 xcode download afnetworking
我一直在谷歌上搜索无济于事,希望对你有所帮助.
我尝试使用AFHTTPRequestOperation流(通过设置outputstream)下载图像.它下载文件,没问题.但进度条不会显示正确,因为totalBytesExpectedToRead始终返回-1,并且仅在下载完成时返回正确的值.
这是流媒体的本质吗?或者我做错了什么?
我的代码如下.
提前致谢!
(void)invokeAsynchronousSTREAMING:(NSString*)path locationToSave:(NSString*)locationToSave参数:(NSDictionary*)paramDict callId:(NSString*)callId {
NSMutableURLRequest *request = [[AFServerAPIClient sharedClient] requestWithMethod:@"GET"
path:path
parameters:paramDict];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
if(locationToSave!=nil) {
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:locationToSave append:NO];
}
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
//DO SOMETHING
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//DO SOMETHING
}
];
[operation setDownloadProgressBlock:^(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
NSLog(@"invokeAsyncronousSTREAMING - Received %lld of %lld bytes", totalBytesRead, totalBytesExpectedToRead);
//DO SOMETHING
}];
[operation start];
Run Code Online (Sandbox Code Playgroud)
} // end invokeAsyncStreaming
| 归档时间: |
|
| 查看次数: |
3108 次 |
| 最近记录: |