使用相机组件,部分华为(荣耀)拍照失败。
- 当前 Bug 的表现(可附上截图)
能看到拍照的界面,但是调用 takePhoto 提示错误 operateCamera:fail:camera has not been initialized
只有部分华为(荣耀)手机出现该情况。ios正常。
如果写一个简单的demo或者官方相机组件的demo也没有问题。
- 相关代码
wxml
< view id = "wrapper" > <!-- 相机 --> < camera id = "camera" device-position = "back" flash = "off" binderror = "error" ></ camera > < cover-view id = "customStyle" > <!-- 点击拍摄 --> < cover-view class = "takePhoto" bindtap = "takePhoto" > < cover-view class = "inside" ></ cover-view > </ cover-view > </ cover-view > </ view > |
js
Page({ data: { // 图片路径 imgUrl: '' }, onLoad: function (options) { this .ctx = wx.createCameraContext() }, // 拍照 takePhoto() { wx.getSetting({ success: (res) => { if (!res.authSetting[ 'scope.camera' ]) { wx.openSetting({ success(res) { if (res.authSetting[ 'scope.camera' ]) { wx.navigateBack({ delete : 1 }) } } }) } else { this .ctx.takePhoto({ quality: 'high' , success: (res) => { this .setData({ imgUrl: res.tempImagePath, oppenPhoto: true }) }, fail: (err) => { console.log(err) } }) } } }) } }) |
2 回复