stopRangingAndMonitoring = async () => { const { identifier, uuid} = this.state; const region = { identifier, uuid }; // minor and major are null here try { await Beacons.stopRangingBeaconsInRegion(region); console.log('Beacons ranging stopped successfully'); await Beacons.stopMonitoringForRegion(region); console.log('Beacons monitoring stopped successfully'); } catch (error) { throw error; } }
componentWillUnMount() { // stop monitoring beacons: Beacons .stopMonitoringForRegion(region) .then(() => console.log('Beacons monitoring stopped succesfully')) .catch(error => console.log(`Beacons monitoring not stopped, error: ${error}`)); // stop ranging beacons: Beacons .stopRangingBeaconsInRegion(region) .then(() => console.log('Beacons ranging stopped succesfully')) .catch(error => console.log(`Beacons ranging not stopped, error: ${error}`)); // stop updating locationManager: Beacons.stopUpdatingLocation(); // remove auth state event we registered at componentDidMount: this.authStateDidRangeEvent.remove(); // remove monitoring events we registered at componentDidMount this.regionDidEnterEvent.remove(); this.regionDidExitEvent.remove(); // remove ranging event we registered at componentDidMount this.beaconsDidRangeEvent.remove(); }