Expo.io Always On Background Location Tracking with watchPositionAsync? - react-native

Do compiled Expo.io React Native applications support "Always On" background location tracking, even when the app is not in use?

Expo just implemented Background Location
Instead of using the watchPositionAsync method, you will have to utilize TaskManager.defineTask method to register the background task out outside of the React event loop. Then, start the task with Location.startLocationUpdatesAsync.

Short answer is no. Quoting the "Why not expo" page:
Expo apps don’t support background code execution (running code when
the app is not foregrounded or the device is sleeping). This means you
cannot use background geolocation, play audio in the background,
handle push notifications in the background, and more. This is a work
in progress.
You will need to detach your app and add this behavior yourself, still doing so you lose some of the expo capabilities.

Related

How to stop other apps push notification from react native app? [duplicate]

A React Native-specific version of this question was asked, but not answered React-Native: How can I disable all push notifications while my app is active?
Essentially, is there a way to remove interruptions while my app is in the foreground? Ideally there would be a "focus" state I put the app into that minimizes disruptions, but I can't find an API like that.
Concretely, part of my app involves meditation states. Getting popups during one of those is distracting, so I'd like to disable banners and alerts while one of those sessions is running.
Happy to hear it's not possible, just haven't actually found that answer yet.
No, you don't have an API or control over other apps notifications. But surely you can control your app notifications. You can handle those notifications without prompting. Let me know if this is helpful.

How to track user location in background, react native?

I am using the react-native-geolocation-service package, and everything works like a charm. But now I am required to track a users location both in the foreground and in the background. I was wandering if the watchPosition method supports background location watching or is it just when in the app? and if it doesn't support it, what would be the alternative?
Thanks
I've used it in the past and it's not straightforward. I tried with the package you mentioned and a few others. I've settled up for the react-native-background-geolocation.
You might encounter problems when switching from the background to the foreground (assuming you also need to track the location in the foreground). They can be fixed by adding a Listener.

Is there an event to listen on for when a React Native app is quit?

Im interested in firing a function when a user quits the app, meaning they bring up multi-tasking and close-out the app.
I'm not talking about navigating back to your home screen and keeping the app in the background.
I'm aware of AppState, but as I said, im looking for the suit scenario, not a change from active, to the background
Is this possible, my componentWillUnmount() is not firing in this case?
Here is an example using an OS background task and additional library. That might be your best bet without using AppState/ComponentDidUnmount() which would only detect active/background status:
https://github.com/billmalarky/react-native-queue#os-background-task-full-example
componentWillUnmount() won't fire because that's only when a component is being removed from the DOM.
The JavaScript engine closes when the app does so there's no other way to communicate with it once the app is closed.

How to implement Background Fetch on React Native | Expo?

There was a task to make push notifications when the application is completely off.
Need to implement some Background Task Manager that will be at intervals such as a minute to check for new notifications for a specific user. In simple words, make a background fetch.
Previously, I implemented push notifications in the application.But they work only when the application is enabled or simply minimized. When the app is completely off Push does not work.
Has anyone done this before ?
I use Expo for this project.

React Native lifecycle and restarts

Firstly, apologies for the slightly open ended questions but I can't find the info I'm looking for in other questions.
I'm trying to understand the lifecycle of a RN app on both iOS and Android. I understand the app bootstraps when you first start it and stays running while the phone is alive, but what happens when the user switches to a different app and comes back, or their screen times out then they switch it back on? It would be really annoying if the app restarted just because they briefly switched to check their email.
My specific use case (not particularly important to this generic question but included for context) is that I'm trying to build a game with socket.io connections and I'm wondering if I can hook into events to see if the app has been in the background or if I even need to. I have found a way of forcing a restart which may be necessary at some points, but I'd rather just try to reconnect things that have disconnected if I can find out when that happens.
Any push in the right direction would be appreciated.
The app doesn't restart when it goes in the background as you describe. The app keeps its state and the user sees the last screen they visited.
You should have a look at react native's AppState
https://facebook.github.io/react-native/docs/appstate
Using AppState you can addEventListeners that capture the change of the app's state like when going to background.
Of course there are also some problems here...
You can't capture the "kill "event. You can only detect if the app is sent to the background but unfortunately you can't detect when the user chooses to "kill" the app
You can't run any code while your app is in the background. This might be serious in your case but you should evaluate it. For example if you have a timer and you sent the app to the background then the timer stops.