uni-app iphone11 系统13.6.1 执行下面的代码闪退 uni.downloadFile
uni-app iphone11 系统13.6.1 执行下面的代码闪退 uni.downloadFile
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Windows | Windows 10 专业版 | HBuilderX |
产品分类:uniapp/App
PC开发环境操作系统:Windows
手机系统:iOS
手机系统版本号:iOS 13.4
手机厂商:苹果
手机机型:iphone11
页面类型:vue
vue版本:vue2
打包方式:云端
操作步骤:
- 执行就闪退
预期结果:
- 不闪退,正常
实际结果:
- 闪退
bug描述:
ios11,系统13.6.1 执行下面的代码闪退 url是
“file:///private/var/mobile/Containers/Data/Application/9FB5030C-1EE4-4AE6-B6EB-BD58C96EF7B6/tmp/com.xbxm.ai-Inbox/滴滴电子发票.pdf”
uni.downloadFile({ url:url,
success:function(data){
console.log('00000000000000000000000000')
console.log(data)
// if(data.statusCode == 200){
// // filePath 可用于 uni.uploadFile 上传的路径
// let path = data.tempFilePath;
// let name = url.split('/').pop()
// _that.sendFile({path, name})
// }
},
fail: (err) => {
console.log('下载失败', err)
}
});
4 回复
console.log都没有走,没有打印
官方能解决一下么?
在 uni-app 中,如果你在使用 uni.downloadFile
时遇到闪退问题,尤其是在 iPhone 11 上运行 iOS 13.6.1 系统时,可能是由于以下几个原因导致的:
1. URL 不合法
- 确保你传递给
uni.downloadFile
的 URL 是有效的,并且是合法的 URL。如果 URL 格式不正确,可能会导致闪退。
uni.downloadFile({
url: 'https://example.com/path/to/file', // 确保 URL 有效
success: (res) => {
console.log('下载成功', res.tempFilePath);
},
fail: (err) => {
console.error('下载失败', err);
}
});
2. 网络请求权限
- 确保在
manifest.json
中配置了网络请求权限。如果应用没有网络权限,可能会导致闪退。
{
"networkTimeout": {
"request": 60000,
"downloadFile": 60000
}
}
3. iOS 系统限制
- iOS 系统对网络请求有一定的限制,尤其是在非 HTTPS 的 URL 上。如果你尝试下载一个非 HTTPS 的资源,可能会导致闪退。确保你使用的 URL 是 HTTPS 的。
uni.downloadFile({
url: 'https://example.com/path/to/file', // 使用 HTTPS
success: (res) => {
console.log('下载成功', res.tempFilePath);
},
fail: (err) => {
console.error('下载失败', err);
}
});
4. 内存不足
- 如果你下载的文件非常大,可能会导致内存不足而闪退。尝试下载较小的文件,或者分块下载。
5. 系统版本兼容性问题
- iOS 13.6.1 可能存在一些兼容性问题。确保你使用的是最新版本的 uni-app 和相关插件。如果可能,尝试在更高版本的 iOS 上测试。
6. 调试与日志
- 使用
console.log
或uni.showModal
来调试代码,查看是否有错误信息输出。你可以在fail
回调中打印错误信息。
uni.downloadFile({
url: 'https://example.com/path/to/file',
success: (res) => {
console.log('下载成功', res.tempFilePath);
},
fail: (err) => {
console.error('下载失败', err);
uni.showModal({
title: '错误',
content: JSON.stringify(err),
showCancel: false
});
}
});