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.66k stars 426 forks source link

IOS Crash on reload while watchPosition #2188

Closed stalteri closed 3 weeks ago

stalteri commented 4 weeks ago

Your Environment

Expected Behavior

no crash

Actual Behavior

IOS crash on reload while watchPosition, reproduced on simulator, did not try on a real device, crashing when reload app (metro server)

Steps to Reproduce

  1. Install and configure plugin
  2. Use watchPosition
  3. Reload app (metro server)

Debug logs

Logs [crash-report.txt](https://github.com/user-attachments/files/17519085/crash-report.txt)
christocracy commented 4 weeks ago

Show me the code that reproduces this.

stalteri commented 3 weeks ago

also have this error in xcode:

Thread 1: "Error when sending event: location with body: {\n activity = {\n confidence = 100;\n type = unknown;\n };\n age = 565;\n battery = {\n \"is_charging\" = 0;\n level = \"-1\";\n };\n coords = {\n accuracy = 10;\n altitude = 0;\n \"altitude_accuracy\" = \"-1\";\n \"ellipsoidal_altitude\" = 0;\n floor = 0;\n heading = \"162.2\";\n \"heading_accuracy\" = 0;\n latitude = \"37.33097983\";\n longitude = \"-122.03063943\";\n speed = \"3.73\";\n \"speed_accuracy\" = 0;\n };\n extras = {\n };\n \"is_moving\" = 1;\n mock = 1;\n odometer = \"2047.4\";\n timestamp = \"2024-10-25T13:41:32.171Z\";\n uuid = \"0AE89EDA-3A27-4B6D-A092-F675912E06F7\";\n}. RCTCallableJSModules is not set. This is probably because you've explicitly synthesized the RCTCallableJSModules in RNBackgroundGeolocation, even though it's inherited from RCTEventEmitter."

christocracy commented 3 weeks ago

Show me the code that reproduces this.

Also, why are you using .watchPosition()? It's not required.

stalteri commented 3 weeks ago

I use .watchPosition() because I need to continuously send location with socket

here are ready and watch functions:

Screenshot 2024-10-25 at 16 53 13
christocracy commented 3 weeks ago

The plug-in already “continuously sends location” automatically when the device is detected to be moving. You only need to call .start().

if you want periodic locations, you’re free to use your own timer and call .getCurrentPosition.

.watchPosition is meant only for use in the foreground, for short periods of time.

it is not required by the plug-in’s core “Philosophy of Operation”.

stalteri commented 3 weeks ago

OK, I'll try to use getCurrentPosition, after weekends

stalteri commented 3 weeks ago

getCurrentPosition work without crashes 🔥 but I get continuous warning - Sending location with no listeners registered if I set empty listener [BackgroundGeolocation.onLocation(() => {})] its gone, but what if I dont need that listener at all? (because I'am using getCurrentPosition only)

christocracy commented 3 weeks ago

but I get continuous warning - Sending location with no listeners registered

You don’t need to worry about that.

if you want that harmless warning to go away, add an empty .onLocation listener — it doesn’t cost anything.

stalteri commented 3 weeks ago

OK, thanks