相机组件重新授权之后无法拍照?
发布于 6 年前 作者 juan35 10436 次浏览 来自 官方Issues

刚进入页面的时候利用

wx.getSetting({

            success(res) {

                console.log(res)

                if (!res.authSetting[‘scope.camera’]) {

                    console.log(‘没有授权’)

                    wx.authorize({

                        scope: ‘scope.camera’,

                        success() {

                            wx.hideLoading()

                            ctx = wx.createCameraContext()

                            _this.cameraSuccess()

                        },

                        failfunction(res) {

                            console.log(res)

                            wx.hideLoading()

                            _this.setData({

                                getCamera: true

                            })

                        }

                    })

                } else {

                    //用户已经授权相机

                    wx.hideLoading()

                    console.log(‘授权了’)

                    ctx = wx.createCameraContext()

                        _this.cameraSuccess()

                }

            }

        })

判断有没有相机授权,点击拒绝之后,利用

wx.openSetting({

            successfunction(res) {

                console.log(res)

                if (res.authSetting[‘scope.camera’]) {

                    _this.setData({

                        getCamera: false,

                    })

                    wx.showModal({

                        title: ‘提示’,

                        content: ‘您已授权成功’,

                        showCancel: false,

                        confirmText: ‘确定’,

                        successfunction(res) {

                            if (res.confirm) {

                                // console.log(‘用户点击了“返回授权”’)

                                _this.cameraSuccess()

                            }

                        }

                    })

                    setTimeout(function() {

                        // _this.cameraSuccess()

                    }, 1000)

                } else {

                    wx.showModal({

                        title: ‘警告’,

                        content: ‘您没有授权成功’,

                        showCancel: false,

                        confirmText: ‘确定’,

                        successfunction(res) {

                            if (res.confirm) {

                                // console.log(‘用户点击了“返回授权”’)

                            }

                        }

                    })

                }

            },

            failfunction(res) {

                console.log(res)

            }

        })

引导用户开启相机权限,但是开启返回之后,就不会调用ctx.takePhoto(),方法都没有走,因为我的手机是redmi k20 pro,调用摄像头的时候会弹出来,这里都没有弹出来,怎么解决,是我代码写的问题吗?

回到顶部