使用相机组件,部分华为(荣耀)拍照失败。
- 当前 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)[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码]})[代码]