Hi,
I’ve used this iBeacons plugin for my android app development
I’ve followed same approach but my iBeacons are not been shown in the result. Later i was searching in the forum then I came across to this thread.
which is exactly the same I facing to, but at the end of that thread the solution is to use “startRangingBeaconsInRegion”
I’ve changed it but still it is not discovering the beacons, I got a doubt on my beacons probably they got damaged, then I used iBeacon transmitter using a mobile app. so technically this should show in the scan result but it is not.
whereas other app like locate, it is able to identify my beacons and also the beacon simulation (iBeacon Transmitter) through mobile app.
could any one suggest me, how I can debug further to know why it is not discovering or resolve this issue?
just to share, so far what I did. Here is my code.
import { Component } from '@angular/core';
import { ChangeDetectorRef } from '@angular/core';
import {Platform} from '@ionic/angular';
import { IBeacon, IBeaconPluginResult } from '@ionic-native/ibeacon/ngx';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
uuid = '11223344-5566-7788-9900-aabbccddeeff';
//uuid = '51A895F4-3FF8-47E8-AD1D-6AA1533BE111';
beaconData = [];
beaconUuid: String;
scanStatus: boolean = false;
private delegate: any = null;
public beaconRegion: any = null;
public iosDevice: boolean = false;
constructor(
private readonly ibeacon: IBeacon, private readonly platform: Platform, private changeRef: ChangeDetectorRef
) {
this.platform.ready().then(() => {
this.requestLocPermissoin();
this.enableDebugLogs();
});
}
ngOnDestroy(){
}
ngOnInit() {
if (! this.platform.is('ios')) {
this.iosDevice = true;
}
}
requestLocPermissoin(): void {
// Request permission to use location on iOS
if (this.platform.is('ios')) {
this.ibeacon.requestAlwaysAuthorization();
console.log(`: request ios permisson`);
}
}
enableDebugLogs(): void {
this.ibeacon.enableDebugLogs();
this.ibeacon.enableDebugNotifications();
}
public onScanClicked(): void {
if (!this.scanStatus) {
this.startScanning();
this.scanStatus = true;
} else {
this.scanStatus = false;
this.stopScannning();
}
}
public stopScannning(): void {
// stop ranging
this.ibeacon.stopRangingBeaconsInRegion(this.beaconRegion)
.then(async () => {
console.log(`Stopped ranging beacon region:`, this.beaconRegion);
})
.catch((error: any) => {
console.log(`Failed to stop ranging beacon region: `, this.beaconRegion);
});
}
startScanning() {
// create a new delegate and register it with the native layer
this.delegate = this.ibeacon.Delegate();
this.ibeacon.setDelegate(this.delegate);
this.beaconUuid = this.uuid;
console.log('--===--- Bluetooth state: ', this.ibeacon.isBluetoothEnabled());
// Check bluetooth status Y.Q
this.ibeacon.isBluetoothEnabled()
.then(
(data) => console.log('-------=== Enabled', data),
(error: any) => console.error('-------=== Disabled', error)
);
// Subscribe to some of the delegate's event handlers
this.delegate.didRangeBeaconsInRegion()
.subscribe(
async (pluginResult: IBeaconPluginResult) => {
console.log('didRangeBeaconsInRegion: ', pluginResult)
console.log('found beacons size: ' + pluginResult.beacons.length)
if (pluginResult.beacons.length > 0) {
this.beaconData = pluginResult.beacons;
this.changeRef.detectChanges(); // Check for data change to update view Y.Q
} else {
console.log('no beacons nearby')
}
},
(error: any) => console.error(`Failure during ranging: `, error)
);
this.delegate.didStartMonitoringForRegion()
.subscribe(
(pluginResult: IBeaconPluginResult) =>
console.log('didStartMonitoringForRegion: ', pluginResult)
,
(error: any) => console.error(`Failure during starting of monitoring: `, error)
);
console.log(`Creating BeaconRegion with UUID of: `, this.uuid);
// uuid is required, identifier and range are optional.
this.beaconRegion = this.ibeacon.BeaconRegion('EST3', this.uuid);
this.ibeacon.startMonitoringForRegion(this.beaconRegion).
then(
() => console.log('Native layer recieved the request to monitoring'),
(error: any) => console.error('Native layer failed to begin monitoring: ', error)
);
this.ibeacon.startRangingBeaconsInRegion(this.beaconRegion)
.then(() => {
console.log(`Started ranging beacon region: `, this.beaconRegion);
})
.catch((error: any) => {
console.error(`Failed to start ranging beacon region: `, this.beaconRegion);
});
}
}