gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 14:45:38 25 4
gpt4 key购买 nike

我正在使用 cordova 文件传输插件从我的应用程序下载文件。

但是,当我使用进度事件向用户显示下载进度条时,每次显示 0% 时都无法正常工作。

这是我用来显示进度事件的代码....

$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;
}
});

任何人都可以帮我解决这个 ios 中的下载进度条问题。

最佳答案

六个月前我遇到了同样的问题,这似乎是 Filetransfer 插件中的错误。

我找到的解决方案是进行此处提到的更改: https://issues.apache.org/jira/browse/CB-9936

In CDVFileTransfer.m, download() method between line 447 to 462

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];

关于javascript - 下载进度事件在使用 cordova 插件文件传输的 ios 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33342436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com