I m using ionic native ibeacon library to detect beacons.I can detect beacons with android but when I try in ios ,i always see an empty beacon array. I tried these things ,but still cant see the beacons in ios (device is iphone 6s plus 11.4.1) (bluetooth service is enabled on device)
- I tried both requestWhenInUseAuthorization and also requestAlwaysAuthorization.
- I add NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription key in info.plist
my code is like this, its working on android device
import { Injectable } from '@angular/core';
import { Platform, Events } from 'ionic-angular';
import { IBeacon } from "@ionic-native/ibeacon";
@Injectable()
export class BeaconProvider {
delegate: any;
region: any;
constructor(
public platform: Platform,
public events: Events,
private iBeacon: IBeacon
) {
this.initialise();
}
initialise(): any {
let promise = new Promise((resolve, reject) => {
if (this.platform.is("cordova")) {
this.iBeacon.requestAlwaysAuthorization();
// ALSO try this one too this.iBeacon.requestWhenInUseAuthorization();
this.delegate = this.iBeacon.Delegate();
this.delegate.didRangeBeaconsInRegion().subscribe(
data => {
this.events.publish("didRangeBeaconsInRegion", data);
//console.log("didRangebeacons__" + JSON.stringify(data)); // empty beacons array
},
error => console.error()
);
this.region = this.iBeacon.BeaconRegion("deskBeacon", "e2c56db5-dffb-48d2-b060-d0f5a71096e0");
this.iBeacon
.startRangingBeaconsInRegion(this.region)
.then(
() => {
resolve(true);
},
error => {
console.error("Failed to begin monitoring: ", error);
resolve(false);
}
);
} else {
resolve(false);
}
});
return promise;
}
}