wx.openBluetoothAdapter({
success: (res) => {
console.log(res, "res");
console.log("蓝牙初始化成功");
},
fail: function (res) {
if (res.errno == 103) { //蓝牙未授权
uni.showModal({
title: "提示",
content:
"未允许本小程序使用蓝牙,请点击“去设置”,在“蓝牙”里选择允许。",
cancelText:"好的",
confirmText: "去设置",
showCancel: true,
success: (res) => {
if (res.confirm) {
wx.openSetting()
}
}
});
} else if (res.errno == 1500102) { //手机蓝牙没开
console.log("手机蓝牙没开1111",res.errno);
uni.showModal({
title: "提示",
content:
"手机蓝牙功能未开启,请在系统设置中打开蓝牙功能,并允许“微信”使用。",
confirmText: "好的",
showCancel: false,
success: (res) => {
if (res.confirm) {
// wx.openSetting()
}
}
});
} else if (res.errno == 3) { //华为手机这个权限没开也会影响蓝牙
uni.showModal({
title: "提示",
content:
"需要开启附近设备权限,请前往系统设置,选择应用和服务->应用管理->微信->其他权限->附近设备打开",
confirmText: "好的",
showCancel: false,
success: (res) => {
if (res.confirm) {
// wx.openSetting()
}
}
});
}
},
});
uniapp查看当前小程序是否授权使用蓝牙
最新推荐文章于 2024-12-31 15:53:25 发布