简体   繁体   English

使用cordova插件文件传输下载进度事件在ios中不起作用

[英]Download progress event is not working in ios using cordova plugin file transfer

I am using cordova file transfer plugin to download files from my app. 我正在使用cordova文件传输插件从我的应用程序下载文件。

But, when I m using progress event to show the user to progress bar on downloading It is not working properly every time it shows 0%. 但是,当我使用进度事件向用户显示下载进度条时每次显示0%时都无法正常工作。

Here is code which I used to show progress event.... 这是我用来显示进度事件的代码....

$cordovaFileTransfer.download(url, targetPath, downloadOptions,
    trustHosts).then(function(result) {
}, function(err) {
}, function(progress) {
    if (progress.lengthComputable) {
        $rootScope.downloadProgress = (progress.loaded / progress.total) * 100;
    } else {
        $rootScope.downloadProgress = (progress.loaded / file_size) * 100;
    }
});

Can anyone please help me out to solve this downloading progress bar issue in ios. 任何人都可以帮我解决ios中的下载进度条问题。

I had the same problem six months ago, it seems to be a bug in the Filetransfer plugin. 六个月前我遇到了同样的问题,它似乎是Filetransfer插件中的一个错误。

The solution I found was to do the changes mentioned here: https://issues.apache.org/jira/browse/CB-9936 我找到的解决方案是执行此处提到的更改: https//issues.apache.org/jira/browse/CB-9936

In CDVFileTransfer.m, download() method between line 447 to 462 在CDVFileTransfer.m中,在第447行到第462行之间的download()方法

 delegate.connection = [[NSURLConnection alloc] initWithRequest:req delegate:delegate startImmediately:NO]; if (self.queue == nil) { self.queue = [[NSOperationQueue alloc] init]; } [delegate.connection setDelegateQueue:self.queue]; @synchronized (activeTransfers) { activeTransfers[delegate.objectId] = delegate; } // Downloads can take time // sending this to a new thread calling the download_async method dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) { [delegate.connection start];} ); 

If I replaced it with the older version of the code, then it works. 如果我用旧版本的代码替换它,那么它的工作原理。

 delegate.connection = [NSURLConnection connectionWithRequest:req delegate:delegate]; if (activeTransfers == nil) { activeTransfers = [[NSMutableDictionary alloc] init]; } [activeTransfers setObject:delegate forKey:delegate.objectId]; 
function (progress) {
                    $timeout(function () {
                        $scope.downloadProgress = (progress.loaded / progress.total) * 100;
                        console.log($scope.downloadProgress)
                    });
                }

Replace your progress function with this function, u can check your result in console 使用此功能替换进度功能,您可以在控制台中检查结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM