transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.62k stars 428 forks source link

cannot read the property ready of null #2089

Open Naveenkumar-1411 opened 1 month ago

Naveenkumar-1411 commented 1 month ago

import React, { useState, useEffect } from 'react'; import { View, Button, Alert, StyleSheet } from 'react-native'; import BackgroundGeolocation from 'react-native-background-geolocation'; import Constants from 'expo-constants'; import * as Application from 'expo-application'; import axios from 'axios'; import BASE_URL from '../../../../utils/Api'; import { useDispatch, useSelector } from "react-redux"; const Homeview = () => { const [isTracking, setIsTracking] = useState(false); const [deviceUuid, setDeviceUuid] = useState('');

const loginUser = useSelector((state) => state.user.user); const employee_id = loginUser.profile.id;

useEffect(() => { // Get the device unique ID const fetchDeviceUuid = () => { const uuid = Constants.platform.android ? Application.getAndroidId() : Constants.installationId; setDeviceUuid(uuid); };

fetchDeviceUuid();

BackgroundGeolocation.onLocation(async (location) => {
  const locationData = {
    device_uuid: deviceUuid,
    employee_id,
    location: {
      coords: {
        latitude: location.coords.latitude,
        longitude: location.coords.longitude,
        altitude: location.coords.altitude,
        accuracy: location.coords.accuracy,
        speed: location.coords.speed,
      },
      is_moving: location.is_moving ? 1 : 0,
      provider: {
        network: location.provider.network || "",
        status: location.provider.status || "",
        gps: location.provider.gps || "",
        enabled: location.provider.enabled || "",
      },
      activity: {
        type: location.activity.type || "",
      },
      battery: {
        is_charging: location.battery.is_charging ? 1 : 0,
        level: location.battery.level,
      },
    },
  };

  try {
    await axios.post(`${BASE_URL}/location/track`, locationData, {
      headers: {
        Authorization: `Bearer ${loginUser.auth_key}`,
      },
    });
  } catch (error) {
    console.error("Error sending location data:", error);
  }
});

// Clean up
return () => {
  BackgroundGeolocation.removeListeners();
};

}, [deviceUuid]);

const startTracking = () => { BackgroundGeolocation.ready({ desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH, distanceFilter: 50, stopOnTerminate: false, startOnBoot: true, debug: false, logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE, }, (state) => { if (!state.enabled) { BackgroundGeolocation.start(); } });

setIsTracking(true);

};

const stopTracking = () => { BackgroundGeolocation.stop(); setIsTracking(false); };

return (

Naveenkumar-1411 commented 1 month ago

WhatsApp Image 2024-07-17 at 3 39 00 PM (1) WhatsApp Image 2024-07-17 at 3 39 00 PM here is the image i have uploaded

Naveenkumar-1411 commented 1 month ago

please some do needfull

christocracy commented 1 month ago

If the method doesn't exist, then your app things the plugin is not installed.

Also, you completely ignored the required issue template so I don't even know anything about your setup.

Your Environment

Expected Behavior

Actual Behavior

Steps to Reproduce

1. 2. 3. 4.

Context

Debug logs

Logs ``` PASTE_YOUR_LOGS_HERE ```
Naveenkumar-1411 commented 1 month ago
"react-native": "0.74.1",
platform :Android,
os Version: Android13,14,
Device ,Vivo y021,iqoo Z7
plugin version:
expo-gradle-ext-vars": "^0.1.2",
    "react-native-background-fetch": "^4.2.5",
    "react-native-background-geolocation": "^4.16.5",
    plugin config:
       [
        "react-native-background-geolocation",
        {
          "license": "my license"
        }
      ],
      [
        "expo-gradle-ext-vars",
        {
          "googlePlayServicesLocationVersion": "21.1.0",
          "appCompatVersion": "1.4.2"
        }
      ],
      "react-native-background-fetch"
    ],
christocracy commented 1 month ago

See the last section of Setup Instructions named "Re-build".

Naveenkumar-1411 commented 1 month ago

whether i need to prebuild and then work on it

christocracy commented 1 month ago

After adding the plug-in, you must “prebuild” or the plug-in doesn’t exist.

Naveenkumar-1411 commented 1 month ago

Wheter i need to convert my Expo App into the native cli

christocracy commented 1 month ago

or eas build

Naveenkumar-1411 commented 1 month ago

if i make eas build how it work if i need to make both Apple and Andoid build it requires Apple id

github-actions[bot] commented 4 days ago

This issue is stale because it has been open for 30 days with no activity.