I'm using Firebase, while my app is in the background and i want to when the database has new data, the notification will be pushed, like this:
message.on('child_added', function(data) {
pushNotification(data);
});
I have searched on Google and found this library: .
Everything works fine, my background job:
const newMessageJob = {
jobKey: "newMessageJob",
job: () => {
pushNotification(newMessage);
}
};
BackgroundJob.register(backgroundJob);
But the problem is here, it's only called at fixed times (looks like setInterval):
BackgroundJob.schedule({
jobKey: "newMessageJob",
period: 1000,
timeout: 1000,
exact: true
});
But i want it to work dynamically (Background Job fired when new data has been added), so how can i solve this problem?
Thanks.
I'm using Firebase, while my app is in the background and i want to when the database has new data, the notification will be pushed, like this:
message.on('child_added', function(data) {
pushNotification(data);
});
I have searched on Google and found this library: https://github./vikeri/react-native-background-job.
Everything works fine, my background job:
const newMessageJob = {
jobKey: "newMessageJob",
job: () => {
pushNotification(newMessage);
}
};
BackgroundJob.register(backgroundJob);
But the problem is here, it's only called at fixed times (looks like setInterval):
BackgroundJob.schedule({
jobKey: "newMessageJob",
period: 1000,
timeout: 1000,
exact: true
});
But i want it to work dynamically (Background Job fired when new data has been added), so how can i solve this problem?
Thanks.
Periodic background tasks while the app is closed can be solved in pure JS (no native code needed) cross platform now with react native queue and react native background task, but what you are wanting to do (run an ongoing service in the background instead of a periodic task) is not possible in React Native currently (and there isn't even a general way to do this natively as far as I understand, apps use workarounds).
The current limitations on cross platform background tasks are as follows: