首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ionic-native angular示例代码到vuejs

ionic-native angular示例代码到vuejs
EN

Stack Overflow用户
提问于 2020-01-10 23:46:38
回答 1查看 295关注 0票数 8

有了离子原生插件,就可以通过原生插件https://ionicframework.com/docs/native/ibeacon使用iBeacons

示例代码是为使用Ionic和AngularJS的人编写的,但我使用的是VueJS,我不知道如何让它工作:

示例代码的Angular版本:

代码语言:javascript
复制
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';

并像这样使用它:

代码语言:javascript
复制
foobar() {
let _ibeacon = IBeacon.Delegate()
  alert('Hi iBeacon');
  _ibeacon.didStartMonitoringForRegion()
    .subscribe(
      data => console.log('didStartMonitoringForRegion: ', data),
      error => console.error()
    );
}

但即使是警报也不会显示。在Vue和ionic中使用iBeacon插件的正确方法是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-15 18:01:53

this repo的Quick起作用了。只是换掉了两个文件。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59684850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档