【问题标题】:I using cordova-plugin-ibeacon but not working(does'nt find beacons in android)我使用cordova-plugin-ibeacon但不工作(在android中找不到信标)
【发布时间】:2017-04-11 11:08:22
【问题描述】:

这里是代码

beacon-provider.ts >>

 initialise(): any {
    let promise = new Promise((resolve, reject) => {

      if (this.platform.is('cordova')) {


        IBeacon.enableBluetooth();

        this.delegate = IBeacon.Delegate();

        this.delegate.didRangeBeaconsInRegion()
          .subscribe(
          data => {
            this.events.publish('didRangeBeaconsInRegion', data);
          },
          error => console.error()
          );

        this.region = IBeacon.BeaconRegion('deskBeacon', '24DDF411-8CF1-440C-87CD-E368DAF9C93E');

        IBeacon.startRangingBeaconsInRegion(this.region)
          .then(
          () => {
            resolve(true);
          },
          error => {
            console.error('Failed to begin monitoring: ', error);
            resolve(false);
          }
          );


      } else {
        console.error("This application needs to be running on a device");
        resolve(false);
      }
    });

    return promise;
  }


}

home.ts >>

export class HomePage {

  beacons: BeaconModel[] = [];
  zone: any;

  constructor(public navCtrl: NavController, public platform: Platform, public beaconProvider: BeaconProvider, public events: Events) {

    this.zone = new NgZone({ enableLongStackTrace: false });

  }

  ionViewDidLoad() {
    this.platform.ready().then(() => {
      this.beaconProvider.initialise().then((isInitialised) => {
        if (isInitialised) {
          this.listenToBeaconEvents();
        }
      });
    });
  }

  listenToBeaconEvents() {
    this.events.subscribe('didRangeBeaconsInRegion', (data) => {

      this.zone.run(() => {

        this.beacons = [];

        let beaconList = data.beacons;
        beaconList.forEach((beacon) => {
          let beaconObject = new BeaconModel(beacon);
          this.beacons.push(beaconObject);
        });

      });

    });
  }

}

在这段代码中,alert(JSON.stringify(data)) 的结果是:

{"eventType":"didRangeBeaconslnRegion","region":{"identifier":"desk beacon","uuid":"24DDF411-8CF1-440C-87CD-E368DAF9C93E","typeName":"BeaconRegion"}, "beacons":[]}

data.beacons 字段为空。

有什么问题?

还有一个问题,我先尝试 BLE-central 插件,但是, 当我使用 BLE-central 插件时,我得到了信号,但如果我从广告中得到这个值,它并没有给我主要的、次要的价值?

【问题讨论】:

  • 我假设您已经编辑了显示的数据结构。信标属性真的为空还是一个空数组?
  • 空数组.."beacons":[] like this

标签: android cordova plugins ionic2 ibeacon


【解决方案1】:

有很多事情可能会导致这种行为:

  • 验证蓝牙是否开启
  • 验证您的应用是否已获得检测蓝牙设备所需的运行时位置权限。转到设置 -> 应用程序 -> [您的应用程序名称] -> 权限,并确保在开关打开的情况下看到位置条目。
  • 使用现成的检测器应用程序验证您的信标实际上正在传输您期望的标识符。在这里试试我的定位应用程序:https://play.google.com/store/apps/details?id=com.radiusnetworks.locate&hl=en

【讨论】:

    猜你喜欢
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-07
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    相关资源
    最近更新 更多