Ionic-Native Angular示例代码转换为Vue.js

8
使用Ionic Native,可以通过本地插件使用iBeacons:https://ionicframework.com/docs/native/ibeacon 示例代码是为了帮助使用AngularJS的Ionic用户编写的,但是我正在使用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插件的正确方式是什么?

1个回答

2
这个存储库的快速使用方法很简单,只需要替换两个文件即可。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接