how to make React native get the notification when the app is killed - react-native

Thanks for help.
I have an idea.
obj-c processes notification and pass the content to rn.
And I will try this.

I don't think you can do anything after the app is killed (because it's killed !).
What you can observe though is when the app goes in background / get back focus. See AppState API in React Native. http://facebook.github.io/react-native/docs/appstate.html#content

Related

React Native How to keep memory after force quitting the app

I deployed my app on TestFlight for beta and i came across 2 major bugs.
My app begins with a welcome screen that I only want to show the user the first time they use the app.
Whenever I force quit the app or background the app for large amount of time it reloads the app back to the welcome screen.
How do i make it that after force quitting or just being off the app for a little while the app would remember to skip the welcome screen.
The idea is the user never sees the welcome or any of those screens again. Is this a memory issue? I am using react navigation to navigate as well.
You need to do this with local storage. I have the same system as you and i use redux with redux persist. I save a flag that the welcome screen has been seen in redux and then use redux persist to make sure that when they close and reopen the app the value will still be there.
if you don't want to use redux/redux persist then you could use good old async storage for this.

Turn off notification light automatically expo

How do i add led light notifications on my react native app that turn off when i press the notification
The short answer is that you cannot do this with ReacNative alone.
The slightly longer answer is that you can control the LED light through Android code. You can read more in this question/answer: How to make notification lights work in react-native on android?

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.

Expo.io Always On Background Location Tracking with watchPositionAsync?

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.

How Can I Detect App Termination of React Native App (esp Android)?

How can I detect termination of a react native app so I can do some cleanup? Currently I only care about this for Android.
You can check AppState Api , it'll tell you about app state like active, background and inactive
Without custom modifications I don't think this is possible, you can however try to trigger your react native code in the native handler for when a view gets destroyed... If possible, you should implement a waiting loop there that can be stopped when your react native cleanup is done.
PS: I did not yet try this out myself!