添加附近的设备权限未开启的报错提示

This commit is contained in:
范鹏 2024-08-29 19:42:52 +08:00
parent 1cc09adb59
commit ed3e3115e3
2 changed files with 12 additions and 4 deletions

View File

@ -24,7 +24,7 @@
const checkResult = await this.checkSetting()
console.log(checkResult)
if(checkResult === true) {
this.initAndListenBluetooth()
this.initAndListenBluetooth(false)
}
},
onShow() {

View File

@ -91,9 +91,9 @@ export const useBluetoothStore = defineStore('ble', {
return { code, data, message }
},
// 初始化并监听
async initAndListenBluetooth() {
async initAndListenBluetooth(tipFlag) {
// 初始化蓝牙
const initResult = await this.initBluetooth()
const initResult = await this.initBluetooth(tipFlag)
if (initResult) {
// 更新蓝牙初始化状态
this.updateInitBluetooth(true)
@ -114,7 +114,7 @@ export const useBluetoothStore = defineStore('ble', {
this.isInitBluetooth = value
},
// 初始化蓝牙模块
initBluetooth() {
initBluetooth(tipFlag = true) {
const that = this
// 初始化蓝牙模块
return new Promise(resolve => {
@ -147,6 +147,14 @@ export const useBluetoothStore = defineStore('ble', {
resolve(true)
return
}
if(err.errno === 3 && tipFlag) {
uni.showModal({
title: '提示',
content: '蓝牙功能需要附近设备权限,请前往设置开启微信的附近设备权限后再试',
showCancel: false,
confirmText: '确定',
})
}
resolve(false)
}
})