我用科尔多瓦 - 插件 - iBeacon显示,但不工作(一点儿也不觉得android的信标)
问题描述:
这里是代码我用科尔多瓦 - 插件 - iBeacon显示,但不工作(一点儿也不觉得android的信标)
信标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中央插件,但是, 当我使用BLE中央插件时,我得到信号但它没有给我主要的次要价值,如果我从广告中获得这个值?
答
有很多事情可能会导致此行为:
- 验证蓝牙是
- 验证您的应用程序已被授予探测蓝牙设备需要运行时位置的权限。进入设置 - >应用程序 - > [你的应用程序名称] - >权限,并确保你看到一个开关打开的位置条目。
- 使用现成的检测器应用程序验证您的信标实际上是否正在传输您期望的标识符。尝试我的定位应用程序在这里:https://play.google.com/store/apps/details?id=com.radiusnetworks.locate&hl=en
+0
我试过了你的定位应用程序,那工作得很好.. –
我假设你已编辑显示的数据结构。信标属性真的为空还是为空数组? – davidgyoung
空数组.. ..“beacons”:[]像这样 –