未命名个人
未命名个人
  • 发布:2025-10-01 11:07
  • 更新:2025-10-09 14:26
  • 阅读:74

【报Bug】相机与选择图片闪退

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win11

HBuilderX类型: 正式

HBuilderX版本号: 4.75

手机系统: Android

手机系统版本号: Android 15

手机厂商: 小米

手机机型: 小米14

页面类型: vue

vue版本: vue3

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

const Select File = async () => {
try {
const res = await uni.chooseImage({
count: 9, // 允许最多选择9张图片
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera']
})
// 判断返回值有效性
if (!res || !res.tempFilePaths || res.tempFilePaths.length === 0) {
uni.showToast({
title: '未选择图片',
icon: 'none'
})
return
}
// 显示等待框
uni.showLoading({
title: '图片上传中...'
})
// 支持多图片上传
for (const filePath of res.tempFilePaths) {
await 上传文件(filePath)
}
// 全部上传完成后关闭等待框
uni.hideLoading()
} catch (error) {
uni.hideLoading()
console.error('选择文件失败:', error)
uni.showToast({
title: '选择图片失败',
icon: 'none'
})
}
}

操作步骤:
const Select File = async () => {  
    try {  
      const res = await uni.chooseImage({  
        count: 9, // 允许最多选择9张图片  
        sizeType: ['original', 'compressed'],  
        sourceType: ['album', 'camera']  
      })  
      // 判断返回值有效性  
      if (!res || !res.tempFilePaths || res.tempFilePaths.length === 0) {  
        uni.showToast({  
          title: '未选择图片',  
          icon: 'none'  
        })  
        return  
      }  
      // 显示等待框  
      uni.showLoading({  
        title: '图片上传中...'  
      })  
      // 支持多图片上传  
      for (const filePath of res.tempFilePaths) {  
        await 上传文件(filePath)  
      }  
      // 全部上传完成后关闭等待框  
      uni.hideLoading()  
    } catch (error) {  
      uni.hideLoading()  
      console.error('选择文件失败:', error)  
      uni.showToast({  
        title: '选择图片失败',  
        icon: 'none'  
      })  
    }  
  }

预期结果:
const Select File = async () => {  
    try {  
      const res = await uni.chooseImage({  
        count: 9, // 允许最多选择9张图片  
        sizeType: ['original', 'compressed'],  
        sourceType: ['album', 'camera']  
      })  
      // 判断返回值有效性  
      if (!res || !res.tempFilePaths || res.tempFilePaths.length === 0) {  
        uni.showToast({  
          title: '未选择图片',  
          icon: 'none'  
        })  
        return  
      }  
      // 显示等待框  
      uni.showLoading({  
        title: '图片上传中...'  
      })  
      // 支持多图片上传  
      for (const filePath of res.tempFilePaths) {  
        await 上传文件(filePath)  
      }  
      // 全部上传完成后关闭等待框  
      uni.hideLoading()  
    } catch (error) {  
      uni.hideLoading()  
      console.error('选择文件失败:', error)  
      uni.showToast({  
        title: '选择图片失败',  
        icon: 'none'  
      })  
    }  
  }

实际结果:
const Select File = async () => {  
    try {  
      const res = await uni.chooseImage({  
        count: 9, // 允许最多选择9张图片  
        sizeType: ['original', 'compressed'],  
        sourceType: ['album', 'camera']  
      })  
      // 判断返回值有效性  
      if (!res || !res.tempFilePaths || res.tempFilePaths.length === 0) {  
        uni.showToast({  
          title: '未选择图片',  
          icon: 'none'  
        })  
        return  
      }  
      // 显示等待框  
      uni.showLoading({  
        title: '图片上传中...'  
      })  
      // 支持多图片上传  
      for (const filePath of res.tempFilePaths) {  
        await 上传文件(filePath)  
      }  
      // 全部上传完成后关闭等待框  
      uni.hideLoading()  
    } catch (error) {  
      uni.hideLoading()  
      console.error('选择文件失败:', error)  
      uni.showToast({  
        title: '选择图片失败',  
        icon: 'none'  
      })  
    }  
  }

bug描述:

调用相机拍照与选择图片会闪退,相机闪退。

2025-10-01 11:07 负责人:无 分享
已邀请:
DCloud_UNI_OttoJi

DCloud_UNI_OttoJi - 日常回复 uni-app/x 问题,如果艾特我没看到,请主动私信

  1. 看代码没事问题,使用空白工程 标准基座试试
  2. 升级 HBuilderX 4.81 再试一下

要回复问题请先登录注册