【问题标题】:Nativescript Bluetooth searchingNativescript 蓝牙搜索
【发布时间】:2021-06-28 18:45:49
【问题描述】:

我正在尝试使用此插件搜索蓝牙设备:

https://github.com/nativescript-community/ble

我总是尝试使用此代码搜索设备:

doStartScanning(){
        {
            this.isLoading = true;
            // reset the array
            this.observablePeripheralArray.splice(0, this.observablePeripheralArray.length);
            this.bluetooth.startScanning(
              {
                filters: [{serviceUUID:'180d'}],   // pass an empty array to scan for all services
                seconds: 4,         // passing in seconds makes the plugin stop scanning after <seconds> seconds
                onDiscovered: function (peripheral) {
                  this.observablePeripheralArray.push(fromObject(peripheral));
                }
              }
            ).then(function() {
              this.isLoading = false;
            },
            function (err) {
                this.isLoading = false;
              alert({
                title: "Whoops!",
                message: err,
                okButtonText: "OK, got it"
              });
            });
          };
    }

我收到此错误:

JS: Unhandled Promise rejection: Permission denied ; Zone: <root> ; Task: null ; Value: Permission denied undefined

蓝牙已启用并从手机授予权限

【问题讨论】:

    标签: bluetooth nativescript


    【解决方案1】:

    这是一个权限错误。将此粘贴到您的 android manifest.xml 中

    <uses-permission android:name="android.permission.BLUETOOTH" />
        <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    

    【讨论】:

      猜你喜欢
      • 2021-03-12
      • 2015-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-18
      • 2020-02-02
      • 1970-01-01
      • 2018-08-15
      相关资源
      最近更新 更多