react-native-beacons-manager icon indicating copy to clipboard operation
react-native-beacons-manager copied to clipboard

regionDidEnter/regionDidExit not firing after kill the app

Open ger86 opened this issue 5 years ago • 6 comments

Version

1.1.0

Platform

iOS | Android

OS version

iOS 12

Steps to reproduce

  1. Kill the app
  2. Get closer / move away to the beacon
  3. The regionDidEnter / regionDidExit is fired in RNiBeacon but it happens before Javascript is loaded, so the listener added through:
  Beacons.BeaconsEventEmitter.addListener('regionDidEnter', b => {
    // code
  });

doesn't get called.

I.E, [self sendEventWithName:@"regionDidEnter" body:event]; is sent before the listener is attached, so I miss the event.

It's important to kill the app in order to reproduce this issue.

Expected behavior

Receive the event in the listener.

Actual behavior

The event regionDidEnter / regionDidExit is not received

ger86 avatar Jan 15 '19 13:01 ger86

@ger86 I have the same problem but I also noticed that after the app was killed, my listeners were deleted. So even if I restart manually the app and trigger an event, [self sendEventWithName:@"regionDidEnter" body:event]; is sent but I get Sending "regionDidEnter" with no listeners registered.

Does it happens to you when restarting the app and triggering an event ?

cedrtang avatar Feb 22 '19 03:02 cedrtang

Nop, it works fine in that case...Maybe you don't have the background modes enabled?

ger86 avatar Mar 05 '19 23:03 ger86

can you please tell me how to make listener working after app killed

Najeisleem avatar Apr 03 '19 19:04 Najeisleem

@Najeisleem For me, the key point to fix this was that on iOS, when an event is triggered and the app is killed, the app is started, then the components are mounted. That s the moment when you should add again your listeners because, right after, the event is propagated to your listeners.

cedrtang avatar Apr 03 '19 19:04 cedrtang

@cedrtang many thanks

Najeisleem avatar Apr 04 '19 21:04 Najeisleem

For me, the app doesn't seem to do anything at all when its killed. I have it set to fire a local push notification on region enter, and it works great when the app is minimized or you're in a different app, but it won't do anything after killing the app entirely. I have background processing enabled (iOS) and i'm not removing listeners on componentWillUnmount either.

Is there a step I'm missing?

edit: I had "Uses Bluetooth LE accessories" enabled, but it seems like the secret sauce was to enable "Acts as a Bluetooth LE accessory" too.

Works now!

RM-Eric avatar Feb 06 '20 20:02 RM-Eric