有一次来反馈 BUG,说真的,是真不想遇到这些低级 BUG。
DownloadFile的 onProgress 声明应该是:
(loaded:number,total:number)=>void
我们再来看微信 creator 这个方法的实现
downloadFile (remoteUrl, filePath, header, onProgress, onComplete) {
var options = {
url: remoteUrl,
success: function (res) {
if (res.statusCode === 200) {
onComplete && onComplete(null, res.tempFilePath || res.filePath);
}
else {
if (res.filePath) {
fsUtils.deleteFile(res.filePath);
}
console.warn(`Download file failed: path: ${remoteUrl} message: ${res.statusCode}`);
onComplete && onComplete(new Error(res.statusCode), null);
}
},
fail: function (res) {
console.warn(`Download file failed: path: ${remoteUrl} message: ${res.errMsg}`);
onComplete && onComplete(new Error(res.errMsg), null);
}
}
if (filePath) options.filePath = filePath;
if (header) options.header = header;
var task = wx.downloadFile(options);
onProgress && task.onProgressUpdate(onProgress);
},
重点是这一行
onProgress && task.onProgressUpdate(onProgress);
直接把这个方法个了微API,在来看下微信的API
https://developers.weixin.qq.com/minigame/dev/api/network/download/DownloadTask.onProgressUpdate.html
微信这个回调传递的是 res 对象,其中有progress、totalBytesWritten、totalBytesExpectedToWrite三个字段。
所以,进度监听在微信上是有问题的。
其他小游戏平台不确定是不是有类似问题,没去看 API 对比,不过建议官方可以去看看 是不是 有同样的问题。
这种问题,我觉得你们真的应该重视下,也不是什么难的问题,就是粗心或者说底层实现的人,对品质把握不高。