Last Method (or function) before app closes in react-native - javascript

I have some data which I want to keep for the duration of the session i.e when the app starts the data loads and can be accessed any time without fetching it again and when the app closes I want to delete the data so that when it restarts I have fresh data

Why not just flush the data when the app starts? You're not guaranteed to know when the app is killed and/or if the JS thread is running.
Your app could exit when fully in a hibernate state, which means the JS thread will not be executing.

Related

Push notification when app is in foreground (using Firebase triggers)

Let's say that there is an update in certain collection and it triggers function that "exports" notification for certain user (token). I have implemented Firebase Functions in JavaScript for Firestore Triggers (onCreate, onUpdate,...) and it works if app is in background.
I want to send a notification whether the application is running or not...
Can user receive notification (lets say onUpdate) if app is in foreground or that feature is not ready yet (since triggers are in beta version)?
Thanks in advance
If depends on whether your message contains a data property, a notification property, or both.
If the message only contains a notification property, it'll delivered to your application code if the app is in the foreground, but handled by the system when the app is in the background.
If your message contains a data property, it'll always be delivered to your application code. If it also contains a notification property, that part will be handled by the system when the app is in the background.
For more on this, see the Firebase documentation on message types.

Listening on a network for data - React Native App and Server

I'm wanting to create a react-native app that pulls data from a database on the same local network but only when there is a change.
The only way I know how to do this currently is have a loop that pulls the same data down from the database every X seconds but surely this is taxing on the database system?
Is there a way of having the database system (server) send a tiny bit of data out across the network telling any of the listening devices that they should update.
Question 1
Any information on the Broadcasting side? (the part that sends the information out that the database has changed)
Question 2
Any information on the Listener side? (that looks for incoming data from the broadcaster saying that the database has changed and they should update)
End Goal
I'm creating a system where If a button is clicked it updates a database and a react native app then displays where the button is clicked for this I need a server that runs a database that is updated when the buttons are pressed and a app that only calls to the server for the information when there's new information on it.

Storing data through app updates in App Store/Google Play with React-Native AsyncStorage

Considering that I have an application in the App Store/Google Play, which will locally save some data in AsyncStorage (React-Native) depending on the user interaction, what will happen with that data if I make an updated version of the app and push it to the App Store/Google Play?
It will still be saved in AsyncStorage?
if you are saving data in your document directory then after updation it will still remain as same. you can overwrite or use save same data. you can also make new directory for new version data also.

How do I respond to an app state change? (React Native)

I want to save the state of my app when the system decides to kill it randomly (when for example it was in the background for a long time). How do I intercept the OS's request to shutdown before my state is lost?
React-native provides an API called AppStateIOS which allows you to get notified when your app switches states. It doesn't provide notifications for all of the app lifecycle state changes, but it does let you know when your app goes to background.
The background state should be enough. When your app goes to the background it gets suspended (assuming you are not using background tasks or background services), and in this state, the OS can terminate your app at any moment if it needs more resources. You won't be able to know when your app gets terminated, so when it goes to the background - this is the point where you should save your state in case your apps gets terminated later.

React Native JS doesn't execute while app is in background

I am trying to get push notifications working in a ios React Native app and am half way there. The one problem im having is that my logic for displaying a Notification while the app is in the background doesn't execute until the app becomes active again. I am using Socket.io and listening for events, but the code to handle (say onChat event) doesn't run until the app is active. I have verified that the socket is still connected.
The one things thats weird is that is works in the simulator but not on my device. Maybe there is performance optimizations that halt JS execution while the app is put in the background.
How can i get my JS to execute while the appstate is in the background?
What im doing is calling a function when the event is recieved over the socket and it runs:
PushNotificationIOS.presentLocalNotification({
alertBody: `New Chat: ${chat.message}`,
});
Thanks to this stack overflow question and answers I was able to find out that code is not executed in the background state to prepare it for the suspended state. The background mode is a transition state to prepare the app to be "screen shotted". The socket will stay connected only for a short time there after, but would eventually get terminated.
In the case with doing a push notifications, I would need to turn that over to Parse or some other service to push a notification to my app while the app is in the background.
Also see http://zeroheroblog.com/ios/what-to-do-when-your-iphone-app-moves-to-the-background

Categories

Resources