-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Headless event listener not called when app is killed #55
Comments
@mathiasmoeller I was having the same issue and fixed it by registering another headless task in |
Hi @NuclearKev , can you share the code how you did that! That will be a big help! |
Sure! I use ClojureScript so it'll look kinda weird but you should be able to get the gist: Somewhere in
Make sure that you register the same event that react-native-boundary does, namely "OnBoundaryEvent".
Then, somewhere else:
and that's literally it! EDIT: You may need to comment out the headless task in react-native-boundary to remove some warnings. |
@NuclearKev
into the index.js? Your answer would be highly appreciated. |
@SufniDroid just like how react-native-boundary does it:
So in our case:
EDIT: or like this if you don't want to have a named function:
|
I hope that works for you guys! I still have yet to figure out iOS.... |
I know that the event gets triggered (if I put a breakpoint on the native code where the event gets triggered, it will stop there) but the code in the event listener doesn't get ran. No idea how to make it run. I was thinking it was maybe related to BGTaskScheduler but the more I look into it the less I think that's it. |
@NuclearKev I am working on a fix for iOS, should come very shortly. |
@cladjules please, keep us posted! :) |
Just tested this ability with react-native-background-geolocation and it worked. So it's definitely possible! Their library is far more complicated than react-native-boundary, so getting it to work would be excellent. Not to mention, the other one causes a lot of money to use on Android... |
Yes a fix for iOS would be awesome! I managed to get it run on Android (the way @NuclearKev suggested). Now iOS needs to work 😁 |
I have opened a PR here: #56 It looks ok on my side, if you could do some testing, that would be great. Thanks |
Thanks, @cladjules I'll be testing that out later today! |
@cladjules your fixes worked! |
@NuclearKev Great. Thanks for the help on Android as well. |
@cladjules where should it be documented? |
@NuclearKev How to add the Headless function, it's not obvious until you find that open issue. |
Does anyone know if there is a way to force iOS to check the location upon app startup? It looks like if the user has the location permission set to "while using," it won't fire the event if they are in the radius when they open the app. EDIT: I tried adding in a function that runs |
The native APIs are designed to work only if the user sets the location permission to always. |
@NuclearKev Where can I put this code? |
It shoud be like this: |
@xoapit I believe that in JavaScript you need to place it in the |
@xoapit @NuclearKev I doubt you need to add anything additional? Should work out of the box, as long as your listeners are not within a React lifecycle. |
on Event doesn't work in Android when the app is killed so I have to use addAppRegistry.registerHeadlessTask outside of React lifecycle as a trick to observe event changes. |
Hey @eddieowens !
When the app is in foreground or background the boundary callbacks work perfectly!
But I am struggling with the Headless part when the app is killed.
In logcat I can see that the event is fired. I see the log message from boundary's
index.js
file:which comes from this part of code here:
But my callback is never executed. I think the issue might be timing.
When the app starts because of a Headless event I can see that boundary receives the event as said above. I added log messages for the Callback Registration and it seems to happen after the Headless event:
I moved the callback registration to the very first line of my
index.js
but the order still seems to be incorrect. Any idea how to solve this? Where should I call theBoundary.on
callback registration in my code?Setup:
Help is very much appreciated :)
The text was updated successfully, but these errors were encountered: