Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

React Native Detecting Beacons in Android/iOS fails on background

$
0
0

React Native Detecting Beacons in Android/iOS fails on background

We used the library https://github.com/MacKentoch/react-native-beacons-managerSo far its working well in foreground but as per checking if its running on the background it stops in a few seconds leaving the background task running but no beacons detected.

We followed the configuration steps documented in Android/iOS and added more for Android. Unfortunately nothing seems to be working and beacon ranging stops though our background service is still running based on the logs.

And it seems like the library we used is not maintained anymore, author is not responding to new PR's and issues.

AndroidBeaconTask

const BeginMonitoringTask = async (eventEmitter: Function) => {    console.log("BeaconMonitoringTask begin....");    const region = {        identifier: '<REGION>',        uuid: '<UUID>'    };    Beacons.detectIBeacons();    Beacons.setForegroundScanPeriod(5*1000);    Beacons.setBackgroundScanPeriod(5*1000);    try {        await Beacons.startRangingBeaconsInRegion(region.identifier, region.uuid)        console.log(`Beacons ranging started succesfully!`)      } catch (err) {        console.log(`Beacons ranging not started`)      }    // Listen for beacon changes    const options = {        taskName: name,        taskTitle: title,        taskDesc: '',        taskIcon: {            name: 'ic_launcher',            type: 'mipmap',        },    };    await BackgroundService.start(async () => {        await new Promise(async (resolve) => {            Beacons.BeaconsEventEmitter.addListener('beaconsDidRange',                (data: any) => {                    const beacons:Beacon[] = data.beacons;                    console.log("BeaconEventEmitter: Background service... beacon data received", data);                    eventEmitter(beacons)                })        });    }, options);};

AndroidManifest

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/><uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /><uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/><uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /><uses-permission android:name="android.hardware.location.gps" /><uses-feature android:name="android.hardware.bluetooth" android:required="true"/><uses-permission android:name="android.permission.BLUETOOTH"/><uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/><uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /><uses-permission android:name="android.permission.FOREGROUND_SERVICE" /><uses-permission android:name="android.permission.WAKE_LOCK" /><uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

Your help is very much appreciated.Thanks


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>