React Native - Expo notification Scheduling - react-native

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.

Related

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

Can I modify expo push notification title/body before showing the notification?

I'm using expo notification service.
I would like to send keys from backend, e.g.
{
title: "TITLE_KEY",
body: "BODY_KEY"
}
then translate it when it comes on the mobile side (based on the key), before showing it, so user would not see the key on notification, just the translated text...
So the question is how could I modify notification before showing it to the user?

Push Notifications with RealmDB 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

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.

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