Flutter Web Firebase handle background message - firebase-cloud-messaging

Is it possible to receive background notifications in flutter web. By following the official documentation, I have managed to receive the background notifications is a serviceworker javascript file. But I am stuck, on how to relay that notification from javascript to dart code?. Tried many samples using js interop etc. But service worker js won't recognise any functions that I wrapped in dart code. Any help?.
My question is I receive background notification in service worker js onBackgroundMessage event, but not sure how to relay that to dart code.

Related

Send SMS within Expo app without redirecting to the device default messaging app

As part of a school project I am working on, I am trying to build a messaging app that utilizes SMS as the default method for sending and receiving SMS without redirecting to the default SMS Messaging App of the device (ie sending/receiving an SMS for my app without redirecting to the Messages app on the iPhone). but I haven't found anything that can be used to achieve this.
PS: One of the requirements of the projects is not using any external library, except for the things provided with Expo,
You will have to use an external library. That feature isnt build in react Native
One external Library would be "https://www.npmjs.com/package/react-native-sms"
The only option you have if you really dont want to use external librarys is, to write your own function, which communicates with the native API

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-firebase - Open app from Headless JS Service / Open app from received notification in background mode

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);
})

Firebase Cloud Messaging with serverside API push for obj-c

currently I working to implement Firebase Push Notification in my apps.
I found this:
[background] Using Firebase Console my apps can get the notification from system tray with remote notification
[foreground] Using Firebase Console my apps can get the notification from log, but i can make it into notification center with local notification
[foreground] Using Our Dashboard which managed by PHP serverside, I can get notification from log, but i can make it into notification center with local notification
The problem is, how can i get the notification (log is fine) if my apps in background with Our Dashboard which managed by PHP serverside?
I found that there is different between json I got from Firebase Console and our managed serverside dashboard, is that a problem that my apps cant handle? and how i can handle it? can I get the sample of the code to solve this problem?
This is the different between json i got from firebase console and our managed serverside dashboard
firebase console
our managed serverside dashboard
What you want to do is possible by using the normal FCM api.
Please review the differences between Display-Message and Data-Message here:
https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
and see all the parameters in the reference page:
https://firebase.google.com/docs/cloud-messaging/http-server-ref

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).