有了离子原生插件,就可以通过原生插件https://ionicframework.com/docs/native/ibeacon使用iBeacons
示例代码是为使用Ionic和AngularJS的人编写的,但我使用的是VueJS,我不知道如何让它工作:
示例代码的Angular版本:
import { IBeacon } from '@ionic-native/ibeacon/ngx';
constructor(private ibeacon: IBeacon) { }
...
// Request permission to use location on iOS
this.ibeacon.requestAlwaysAuthorization();
// create a new delegate and register it with the native layer
let delegate = this.ibeacon.Delegate();
// Subscribe to some of the delegate's event handlers
delegate.didRangeBeaconsInRegion()
.subscribe(
data => console.log('didRangeBeaconsInRegion: ', data),
error => console.error()
);
delegate.didStartMonitoringForRegion()
.subscribe(
data => console.log('didStartMonitoringForRegion: ', data),
error => console.error()
);
delegate.didEnterRegion()
.subscribe(
data => {
console.log('didEnterRegion: ', data);
}
);
let beaconRegion = this.ibeacon.BeaconRegion('deskBeacon','F7826DA6-ASDF-ASDF-8024-BC5B71E0893E');
this.ibeacon.startMonitoringForRegion(beaconRegion)
.then(
() => console.log('Native layer received the request to monitoring'),
error => console.error('Native layer failed to begin monitoring: ', error)
);但是..。我期望在VueJS中工作的内容如下:
在我的组件之上导入它:import { IBeacon } from '@ionic-native/ibeacon/ngx';
并像这样使用它:
foobar() {
let _ibeacon = IBeacon.Delegate()
alert('Hi iBeacon');
_ibeacon.didStartMonitoringForRegion()
.subscribe(
data => console.log('didStartMonitoringForRegion: ', data),
error => console.error()
);
}但即使是警报也不会显示。在Vue和ionic中使用iBeacon插件的正确方法是什么?
发布于 2020-01-15 18:01:53
this repo的Quick起作用了。只是换掉了两个文件。
https://stackoverflow.com/questions/59684850
复制相似问题