123456789101112131415161718192021222324252627282930313233343536 |
- module.exports = {
- openBluetoothAdapter: openBluetoothAdapter,
- }
- // 打开蓝牙权限
- function openBluetoothAdapter() {
- return new Promise((resolve, reject) => {
- wx.openBluetoothAdapter({
- success: function (res) {
- resolve(true);
- },
- fail: function (res) {
- if (res.errno == 103) {
- wx.showModal({
- title: '提示',
- content: '需要您的蓝牙权限才能使用此功能,是否前往设置授权?',
- showCancel: true,
- success: (modalRes) => {
- if (modalRes.confirm) {
- wx.openSetting({
- success: (settingRes) => {
- resolve(settingRes.authSetting['scope.bluetooth'] ? true : false);
- }
- });
- } else if (modalRes.cancel) {
- resolve(false);
- }
- }
- });
- } else {
- resolve(false);
- }
- }
- })
- });
- }
|