gpt4 book ai didi

vue.js - ionic 原生角度示例代码到 vuejs

转载 作者:行者123 更新时间:2023-12-03 06:36:15 24 4
gpt4 key购买 nike

使用 Ionic Native,可以通过 native 插件使用 iBeacons:https://ionicframework.com/docs/native/ibeacon

示例代码是为使用 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 插件的正确方法是什么?

最佳答案

快的this repo工作。只需要替换两个文件。

关于vue.js - ionic 原生角度示例代码到 vuejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59684850/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com