小编Eve*_*Eve的帖子

setDownloadProgressBlock中的totalBytesExpectedToRead保持为-1,直到下载完成

我一直在谷歌上搜索无济于事,希望对你有所帮助.

我尝试使用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

xcode download afnetworking

6
推荐指数
2
解决办法
3108
查看次数

标签 统计

afnetworking ×1

download ×1

xcode ×1