Push Notifications with RealmDB React Native - react-native

I'm building a app and i need a way to make a push notification according a date stored in the Database (RealmDB), how can I do this? ? There's a way to do it without make the app run in background and executing querys ? I don't want spend to many resources.

Have a try by using react-native-push-notification npm to schedule local notifications.
Example code:
PushNotification.localNotificationSchedule({
message: "My Notification Message", // (required)
date: new Date(Date.now() + (60 * 1000)), // in 60 secs
actions: ["ReplyInput"],
reply_placeholder_text: "Write your response...", // (required)
reply_button_text: "Reply" // (required)
});
Check out the official docs for more understanding
https://github.com/zo0r/react-native-push-notification

Related

React Native - Expo notification Scheduling

Im building a react native App using expo. Im able to send notifications daily like so
Notifications.scheduleNotificationAsync({
content: {
title: "Reminder",
body: "lorem ipsum",
},
trigger: {
hour: 12,
minute: 30,
repeats: true,
},
});
My goal is to send a reminder to the user every day at the same time. I want to send a different reminder message each day say from a database or an array of messages, how do I go about doing that? been stuck for a while
This method to schedule notification does not allow specific code to run when the notification is fired. If you have the message you want to send for the next time, you can fetch that data the moment you schedule the notification. Otherwise, I think you should do that on your server-side application using expo's push API with some kind of cron job.
Another alternative could be the BackgroundFetch api, but you'll need to code some logic to re-schedule the task to fetch the data and send the notification.

Cannot register device with TalkJs for push notifications

I am working on a React Native app that uses TalkJS. We want users to get a push notification for every message they receive. The messages are going through but we aren't getting notifications. We have uploaded our .p12 to the TalkJS dashboard and followed the docs for setting up a React Native project. Below is the relevant code we're injecting to the TalkUI loadScript. We followed https://talkjs.com/docs/Features/Notifications/Mobile_Push_Notifications.html
const res = await window.talkSession.registerDevice({ platform: "ios", pushRegistrationId: "${deviceToken}"});
alert("registering deviceToken ${deviceToken} response: " + res)
We are getting the alert with the correct deviceToken but this method does not return anything. We tried .then and an error first callback but nothing is coming back from this method.
Edit: this method is not designed to return anything, so the response is expected to be empty.
The Promise was designed to not return anything as Kapobajza mentioned.
From their support chat: "We have an issue regarding push notifications on iOS when using React Native."
Edit: this issue has been resolved. In addition to work that needed to be done by the TalkJS team, push notifications require a user to have a 'role', as is very loosely implied in the Overview for Push Notifications

React native callkeep incoming call expiration time

I'm using callkeep to show an incoming call screen when a VoIP push notification is triggered. What I want to accomplish, is to ring the user for just 20 seconds. In case the user never answers, the incoming call screen should just disappear. How can I do that with callkeep?
Should it be modified in the javascript code or in the AppDelegate?
There's a solution, which is done on front end part.
First of all, run
npm i react-native-background-timer
This will help you run scheduled tasks when the app is closed.
Then, you will need to add the listener:
RNCallKeep.addEventListener("didDisplayIncomingCall", onIncomingCallDisplayed);
Which is fired when call is displayed.
And then implement it like this:
const onIncomingCallDisplayed = ({callUUID, handle, fromPushKit, payload,}) => {
BackgroundTimer.setTimeout(() => {
RNCallKeep.endAllCalls();
}, 120000);
};
Where 120000 is time in milliseconds when you want to end the call.
You could also add a backend request to notify your server that the call is rejected.

For an unejected expo app, how to do location tracking in background (periodically if location changes frequently) to prevent app from being killed?

For an expo app that is not ejected and runs in the background, my goal is to do a location tracking periodically or when location changes.
I am sticking with Expo's base APIs including its Location, TaskManager API.
Location tracking only works for a first couple of times before it completely stops.
Following what was written in the Documentation here: https://docs.expo.io/versions/v32.0.0/sdk/location/, I was able to make an app that tracks location with the API: Location.startLocationUpdatesAsync of Expo. I had also defined a "Expo.TaskManager" and this should log a new location every time a new location is detected.
However, if the app runs in the background for more than a few seconds, geolocation service tracking no longer works. No further logging will not be written in the console.
Define Task:
TaskManager.defineTask(PUSH_LOCATION_IN_BACKGROUND, ({ data, error }) => {
if (error) {
return;
}
if (data) {
const { locations } = data;
console.log('locations are ', locations)
}
});
Start (register) the task:
await Location.startLocationUpdatesAsync('PUSH_LOCATION_IN_BACKGROUND', {
accuracy: Location.Accuracy.Balanced,
distanceInterval:3,
});
I expect that every time I change the location of my device (by either moving to a new location of faking my GPS data), I would receive a logging of the new location if the app runs in the background. However, as soon as the app enters the background, it only logs the data for a couple of times before it completely stops.
I would expect that the app will run stably in the background and if possible, avoid being killed by the OS even if the resource consumption in the device is already high.
And as someone who is not experienced in Android developemnt, do I need to set up an undismissable (user cannot dismiss it nor remove it by clicking on it) notification in order to keep the background task of the app alive? Can I do it with an unejected Expo app.

How to show an notification after successful app update via Code Push

I'm using code-push to update my react-native app. I do not want to update it every time via App Store.
I'm using installMode ON_NEXT_RESUME, thus the update is downloaded but not installed immediately. The new content will be available the next time the app is resumed or restarted, whichever event happens first. (if the app was inactive for 10 mins)
My code is as follows:
componentDidMount() {
codePush.sync({ installMode: codePush.InstallMode.ON_NEXT_RESUME,
minimumBackgroundDuration: 60 * 10 });
}
But the problem is than the app is updated but the user doesn't know it.
Is there any way to show an notification of something like that to user after successful update?
You can use
codePush.SyncStatus.UPDATE_INSTALLED
https://github.com/Microsoft/react-native-code-push/blob/master/docs/api-js.md#codepushsync