permissionUtil.js 982 B

123456789101112131415161718192021222324252627282930313233343536
  1. module.exports = {
  2. openBluetoothAdapter: openBluetoothAdapter,
  3. }
  4. // 打开蓝牙权限
  5. function openBluetoothAdapter() {
  6. return new Promise((resolve, reject) => {
  7. wx.openBluetoothAdapter({
  8. success: function (res) {
  9. resolve(true);
  10. },
  11. fail: function (res) {
  12. if (res.errno == 103) {
  13. wx.showModal({
  14. title: '提示',
  15. content: '需要您的蓝牙权限才能使用此功能,是否前往设置授权?',
  16. showCancel: true,
  17. success: (modalRes) => {
  18. if (modalRes.confirm) {
  19. wx.openSetting({
  20. success: (settingRes) => {
  21. resolve(settingRes.authSetting['scope.bluetooth'] ? true : false);
  22. }
  23. });
  24. } else if (modalRes.cancel) {
  25. resolve(false);
  26. }
  27. }
  28. });
  29. } else {
  30. resolve(false);
  31. }
  32. }
  33. })
  34. });
  35. }