How to detect if in range of beacon ionic 3


#1

Hello, I am following a sample code posted by Ionic 3 that implements IBeacons with Ionic 3. What I want to do now is display a message if I come close to the beacon specified. How would I go about that? This is what I see in my console and here is my code.

import { Component } from '@angular/core';

import { NavController } from ‘ionic-angular’;
import { IBeacon } from ‘@ionic-native/ibeacon’;
@Component({
selector: ‘page-about’,
templateUrl: ‘about.html’
})

export class AboutPage {

constructor(public navCtrl: NavController, private ibeacon: IBeacon) {}

// Request permission to use location on iOS
scan(){

// 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(’’,’’); // left blank because I didn’t want to put my information

this.ibeacon.startMonitoringForRegion(beaconRegion)
.then(
() => console.log(‘Native layer received the request to monitoring’),
error => console.error('Native layer failed to begin monitoring: ', error)
);
}

}