Solution 1 :
A few basic troubleshooting steps to perform:
-
Check what log messages to you see when you run it. This may give you a clue where it is failing.
-
Confirm if your app has successfully been granted location permission in settings for your app. The instructions to do so vary by platform. if properly configured, you should see a location entry in your app’s permissions list in settings with location granted.
-
Verify that your uuid, major and minor are correct in this statement:
new BeaconRegion(id, uuid, 100, 1)
— if you run an off-the shelf beacon detector like Locate Beacon on the same phone, does it detect the beacon with those same identifiers?
Solution 2 :
Solutions:
-
Add to
app.gradle
:dependencies { compile 'org.altbeacon:android-beacon-library:2.15.1' }
-
Add this plugin: nativescript-community/ble
-
Add to AndroidManifest permissions:
ACCESS_FINE_LOCATION
In my case this solution detected my beacon.
Problem :
I am using this plugin in Nativescript to use Beacon with the following code:
import {Observable} from 'tns-core-modules/data/observable';
import {
BeaconRegion, Beacon, BeaconCallback,
BeaconLocationOptions, BeaconLocationOptionsIOSAuthType, BeaconLocationOptionsAndroidAuthType
} from 'nativescript-ibeacon/nativescript-ibeacon.common';
import {NativescriptIbeacon} from 'nativescript-ibeacon';
export default class BeaconAdapter extends Observable implements BeaconCallback{
private nativescriptIbeacon: NativescriptIbeacon;
public message: string = 'Init';
private region: BeaconRegion = null;
constructor(id: string, uuid: string) {
super();
let options: BeaconLocationOptions = {
iOSAuthorisationType: BeaconLocationOptionsIOSAuthType.Always,
androidAuthorisationType: BeaconLocationOptionsAndroidAuthType.Fine,
androidAuthorisationDescription: 'Location permission needed'
};
this.nativescriptIbeacon = new NativescriptIbeacon(this, options);
this.region = new BeaconRegion(id, uuid, 100, 1);
}
start() {
this.message = 'start';
if (!this.nativescriptIbeacon.isAuthorised()) {
console.log('NOT Authorised');
this.nativescriptIbeacon.requestAuthorization()
.then(() => {
console.log('Authorised by the user');
this.nativescriptIbeacon.bind();
}, (e) => {
console.log('Authorisation denied by the user');
})
} else {
console.log('Already authorised');
this.nativescriptIbeacon.bind();
}
}
stop() {
this.message = 'stop';
this.nativescriptIbeacon.stopRanging(this.region);
this.nativescriptIbeacon.stopMonitoring(this.region);
this.nativescriptIbeacon.unbind();
}
onBeaconManagerReady(): void {
console.log('onBeaconManagerReady');
this.nativescriptIbeacon.startRanging(this.region);
this.nativescriptIbeacon.startMonitoring(this.region);
}
didRangeBeaconsInRegion(region: BeaconRegion, beacons: Beacon[]): void {
//console.log('didRangeBeaconsInRegion: ' + region.identifier + ' - ' + beacons.length);
//this.message = 'didRangeBeaconsInRegion: ' + (new Date().toDateString());
for (let beacon of beacons) {
console.log('B: ' + beacon.proximityUUID + ' - ' + beacon.major + ' - ' + beacon.minor + ' - ' + beacon.distance_proximity + ' - ' + beacon.rssi + ' - ' + beacon.txPower_accuracy );
}
}
didFailRangingBeaconsInRegion(region: BeaconRegion, errorCode: number, errorDescription: string): void {
console.log('didFailRangingBeaconsInRegion: ' + region.identifier + ' - ' + errorCode + ' - ' + errorDescription);
}
didEnterRegion(region: BeaconRegion) {
//console.log(region);
console.log('Did enter Region ' + region.identifier);
}
didExitRegion(region: BeaconRegion) {
//console.log(region);
console.log('Did leave Region ' + region.identifier);
}
}
But when It starts to monitoring or ranging, does not detect any device even when I have one emitting next to device where I’m testing
And other question, when the app is running on background, the app crashe with this error(using this plugin)
Not allowed to start service Intent app is in background uid UidRecord