相关疑难解决方法(0)

Ionic2:取消订阅事件以避免重复条目?

我已经按照本教程概述了在Ionic 2应用程序中添加监控信标.我有它工作得很好:当视图加载时,它初始化并开始监听信标:

home.ts

    ionViewDidLoad() {
        this.platform.ready().then(() => {
            this.beaconProvider.initialise().then((isInitialised) => {
                if (isInitialised) {
                    this.listenToBeaconEvents();
                }
            });
        });
    } 
Run Code Online (Sandbox Code Playgroud)

这将调用listenToBeaconEvents函数,该函数使用所有信标填充视图中的列表:

home.ts

    listenToBeaconEvents() {
        this.events.subscribe(‘didRangeBeaconsInRegion’, (data) => {

            // update the UI with the beacon list
            this.zone.run(() => {

                this.beacons = [];

                let beaconList = data.beacons;
                beaconList.forEach((beacon) => {
                    let beaconObject = new BeaconModel(beacon);
                    this.beacons.push(beaconObject);
                });

            });

        });
    }
Run Code Online (Sandbox Code Playgroud)

我可以使用this.beaconProvider.stopRanging()以下函数调用函数来停止测距:

信标provider.ts

    stopRanging() {
        if (this.platform.is('cordova')) {
            // stop ranging
            this.ibeacon.stopRangingBeaconsInRegion(this.region)
                .then(
                () => {
                    console.log('Stopped …
Run Code Online (Sandbox Code Playgroud)

ibeacon ionic-framework ionic2

2
推荐指数
1
解决办法
5934
查看次数

标签 统计

ibeacon ×1

ionic-framework ×1

ionic2 ×1