uni-app中uni.chooseImage在微信小程序 ios12,微信版本8.0.14下无法调起摄像头

uni-app中uni.chooseImage在微信小程序 ios12,微信版本8.0.14下无法调起摄像头

开发环境 版本号 项目创建方式
Windows 10 家庭中文版 10.0.18363 HBuilderX
# 产品分类
uniapp/小程序/微信

## 示例代码:
```javascript
export const chooseImage = (count=9) => {  
    return new Promise((resolve,reject) => {  
        uni.chooseImage({  
            count, //默认9  
            sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有  
            sourceType: ['album', 'camera '], //从相册选择  
            success: async (res) => {  
                /* 压缩 H5不支持压缩 */  
                // #ifdef !H5  
                for (let index in res.tempFiles) {  
                    if(res.tempFiles[index].size>200*1000){//大于200KB压缩  
                        let cImg = await compressImage(res.tempFiles[index].path,80)  
                        console.log(cImg)  
                        if(cImg.err) continue  
                        res.tempFiles[index].path = cImg.tempFilePath  
                    }  
                }  
                // #endif  
                resolve(res.tempFiles)  
            },  
            fail(err) {  
                uni.hideLoading()  
                reject(err)  
            }  
        });  
    })  
}

操作步骤:

  1. 写上按钮,添加点击事件
  2. 在点击事件中调用uni.chooseImage,并将sourceType设置为 [‘album’, 'camera ']

预期结果:

ios可以调起摄像头拍照

实际结果:

ios无法调起摄像头拍照

bug描述:

uni.chooseImage 在微信小程序 ios12,微信版本8.0.14 无法调起摄像头


更多关于uni-app中uni.chooseImage在微信小程序 ios12,微信版本8.0.14下无法调起摄像头的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

直接使用微信小程序(不使用 uni-app )测试一下,如果仍然有问题,反馈到微信小程序社区

更多关于uni-app中uni.chooseImage在微信小程序 ios12,微信版本8.0.14下无法调起摄像头的实战教程也可以访问 https://www.itying.com/category-93-b0.html


根据您提供的代码和描述,问题很可能出在 sourceType 参数的格式上。

在您的示例代码中:

sourceType: ['album', 'camera '], //从相册选择

请注意 'camera ' 这个字符串末尾有一个多余的空格。这会导致微信小程序API无法正确识别该参数值。

解决方案: 将代码修改为:

sourceType: ['album', 'camera'], // 注意这里移除了camera后面的空格

原因分析:

  1. uni.chooseImagesourceType 参数要求严格的字符串值:'album'(相册)或 'camera'(相机)
  2. 微信小程序底层API对参数值匹配是精确匹配,'camera '(带空格)不等于 'camera'
  3. iOS系统对权限和API调用较为严格,这种格式问题在特定版本组合下更容易暴露

其他建议检查项:

  1. 确保微信小程序已获取相机权限(首次使用时会弹窗请求)
  2. 检查 app.json 中是否配置了相机权限:
"requiredPrivateInfos": ["chooseImage", "camera"]
回到顶部