react-native-firebase - Open app from Headless JS Service / Open app from received notification in background mode - react-native

I read
How to handle notification when app in background in Firebase
Open app on firebase notification received (FCM)
But these aren't the solution for react-native-firebase.
I'm using react-native-firebase to handle notifications. In foreground, everything works well. I stuck with background state.
I'm working on a chat project and making 1-to-1 call feature. I push data-notification to clients when they have a call. In iOS, I used CallKit when client received notification, and it worked fine. But in Android I have a problem:
I can show ConnectionService UI for a call, but can't connect to my web socket server because it runs on Headless JS service. So I tried to auto open the app. I want to show a call screen as Skype, and accept/deny the call. (Skype can launch the app when I have a call)
Summary, successful steps:
Receive call notification in foreground state and show calling screen.
Receive call notification in background/closed state and show calling screen on iOS.
Receive call notification in background/closed state on Android.
Stuck here:
Show calling screen in background/closed on Android ???
TL;DR - How to launch/run/open Android app from Headless JS Service?
I dig into react-native-firebase, it catches the notification on onMessageReceived and send notification message to Headless JS Service.
// If the app is in the background we send it to the Headless JS Service
Intent headlessIntent = new Intent(
this.getApplicationContext(),
RNFirebaseBackgroundMessagingService.class
);
headlessIntent.putExtra("message", message);
this
.getApplicationContext()
.startService(headlessIntent);
HeadlessJsTaskService.acquireWakeLockNow(this.getApplicationContext());
Any help would be appreciated

This library is helpful to open app from background state.
React Native Launch Application
If your app is quit from background state
you've to register registerHeadlessTask in index.js like this
AppRegistry.registerHeadlessTask(
'ReactNativeFirebaseMessagingHeadlessTask',
() => notificationActionHandler,
);
and in notificationActionHandler function call libraries function to open app
If your app is in background you can subscribe this
messaging().setBackgroundMessageHandler(remoteMessage => {
console.log('setBackgroundMessageHandler', remoteMessage.data);
})

Related

displaying notifications when the app is killed - React Native

I have a problem with diplaying notification while running socket connection in the background service i'm using react-native-backgound-action.
Problems i have right now:
when notification is sent from the backend nothing is been shown i'm using "stompJS" as socket connection and notifee as notification package.
react native background actions use forground service that shows a permanent notification in android.
i have tried to run notification in background

How to handle push notification when application is killed

Pardon me if this question has been asked before, I just couldn't find the answer.
I have an react native application, it has calling feature using .Net Core SignalR (For signalling) and webRTC for actual calling. There are three scenarios out of which my application works fine in two scenarios:
Application is in foreground: For this I simply inform other client that X is calling you (using signals from SignalR).
Application is in background: For this I send push notification to the client which is read by the application (notification listener) which in turns opens up the call accept/decline window.
I am struggling with scenario 3:
Application has been killed (from recent apps etc.) and is now not in background in this scenario I only receive the push notification but call windows doesn't open but if I open up that notification I can see the calling window as intended. I need a solution which will open up the calling window automatically just like it does in scenario 1 & 2. How can I listen to push notifications when the application is dead? So that I can show the call window?
I am looking for a solution that would preferably work both on Android and iOS and I am using FCM Push notifications. I am also open to solutions other than push notifications as long as they work correctly.
For supporting to android and iOS you can use
import messaging from "#react-native-firebase/messaging";
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
// handle your notification message here
}

React Native - Get initial route when App is opened from a notification

I'm using react-native and onesignal to handle notification.
If you press the notification when the app is in the background, i'll catch the 'opened' event, and redirect to the correct route (in the notification metadata)
But when the app is closed, the click on the notification just opens the app, without firing the 'opened' event.
How can i fetch the initial pressed notification metadata ?
Thanks
If you are using RNFirebase Cloud Messaging, you can use the proper listener getInitialNotification where you can catch when the notification is opened while the app is closed. Follow that guide Notifications - Handling Interaction for more infos.

Push notifications using ConnectyCube on React Native

I'm trying to using push notifications using ConnectyCube on React Native. Main problem is that if I send a notification from the admin panel of ConnectyCube (or from source code), the admin panel says that the notification has been successfully delivered, but nothing happens on the android emulator. Maybe someone can think that there are some bugs client-side in the implementation of my onMessageListener:
notificationListener = firebase.notifications().onNotification((notification) => {
console.log("Hi!")
});
Anyway, if I try to send a notification through the Firebase console, all works and I receive the notification. Can you help me?
It seems that you are using a wrong method: https://rnfirebase.io/docs/v5.x.x/notifications/introduction
The React Native Firebase Notifications Module deals with notification-only and notification + data FCM remote messages.
For data-only FCM messages please see the Messaging module.
ConnectyCube sends a data push messages.
Therefore, please try using Messaging module according to this guide:
https://rnfirebase.io/docs/v5.x.x/messaging/receiving-messages

WL push notification callback not being invoked in iOS when app is in background

We have push notifications working successfully. Backend event source is a Worklight adapter written in JS using the 'WL.Server.createDefaultNotification' and 'WL.Server.notifyAllDevices' API calls to send unicast notifications. In the front-end, the app is registered for push notification call back using 'WL.Client.Push.registerEventSourceCallback' JS API.
These particular scenarios are not working:
App is open in the background after login. Notification message is received, but user does not tap notification banner message - and instead just opens app by touching app icon. Notification callback method is not called - and subsequently payload from the backend is not available for the method.
App is open in the background after login. Notification message is received which only has iOS badge change and payload but no notification message for the banner or lock screen. In which case user has nothing to tap on. When user opens the app again - notification callback is not called.
Knowledgecenter documentation seems to indicate that the callback method should be getting invoked even if the app is running in the background. This is with Worklight 6.2.0.1.
Push is indeed supposed to work as you've describe. This is a bug.
This is no manual workaround for this.
If you are an IBM customer or Business Partner you will need to open a PMR (support ticket).