REACT NATIVE : ERROR Invariant Violation: No callback found with cbID 747 and callID 373 for RNBackgroundGeolocation.watchPosition

39 views Asked by At

I'm currently using the react-native-background-geolocation library in my React Native application for geofencing and updating the user's current location on a Google Map. Everything was working smoothly until recently, when I started encountering the following error:

ERROR Invariant Violation: No callback found with cbID 747 and callID 373 for RNBackgroundGeolocation.watchPosition - most likely the callback was already invoked. Args: '[1]', js engine: hermes

1

There are 1 answers

0
Jasim Khan On
This error typically occurs when the user has disabled location services 
on their device. To prevent this error from occurring, you can check 
whether location services are enabled before calling the react-native- 
background-geolocation functions to get the current location.

One way to achieve this is by using the react-native-android-location- 
enabler library. You can install it using npm:

npm install react-native-android-location-enabler

import { promptForEnableLocationIfNeeded } from 'react-native-android- 
location-enabler';
import { Platform } from 'react-native';

async function handleCheckPressed() {
if (Platform.OS === 'android') {
try {
  const enableResult = await promptForEnableLocationIfNeeded();
  console.log('enableResult', enableResult);
  // Handle enableResult based on your application's logic
 } catch (error: unknown) {
  if (error instanceof Error) {
    console.error(error.message);
    // Handle the error appropriately
  }
 }
 }
}

By using this approach, you can ensure that the necessary location 
services are enabled before making calls to react-native-background- 
 geolocation, thereby preventing the occurrence of the error.