iOS local notification in the foreground mode doesn't show notification!
Hello, @zo0r . I am now using this library for local notification functions and it's not showing the notifications when the app is in foreground mode. Can you teach me how to show notification in foreground mode? Thanks
This library uses React Native implementation of push notifications on iOS so consult with their documentation (https://facebook.github.io/react-native/docs/pushnotificationios.html) or open an issue on React Native repository
I checked for that. but there was no answer on react native. In native ios development, there was a solution and that's why I thought RN can also have its own solution.
I have same issue on iOS. When the app is active, the notification doesn't show... However, onNotification did trigger... when the app is in background, the notification shows.
any idea?
I have the same issue I'm trying to figure it out.
Anyone able to solve this issue? Having similar issue..
@zootopia106 iOS 10+ change this behavior. The notifications will show on notification center only if app is killed or in background. When app is in foreground, will fire the event onNotification, but not show in notification center, so you need implement you own way to notify the user in this case.
This will work for you. Notification will be shown when the app is in background and also when it's in foreground (open) :
FCM.on(FCMEvent.Notification, notif => {
// if (notif.fcm && notif.fcm.body) {
/* Create local notification for showing in a foreground */
console.log(" >> notificationListener: ", notif)
console.log(" success register fcm >> notificationListener: ", notif)
if (notif.local_notification) return;
FCM.presentLocalNotification({
body: notif.fcm.body,
priority: "high",
title: notif.fcm.title,
sound: "default",
show_in_foreground: true,
local_notification: true,
"large_icon": "ic_launcher",// Android only
icon: "ic_launcher",
"show_in_foreground": true, /* notification when app is in foreground (local & remote)*/
vibrate: 300, /* Android only default: 300, no vibration if you pass null*/
"lights": true, // Android only, LED blinking (default false)
status: "400"
});
})
local_notification: true
has been added to avoid infinite loop of messages on iOS device.
Thanks for your help , @SFRohan If so, do i have to integrate FCM apart from this library?
Hi @zootopia106 , yes you would need to integrate FCM for this from "react-native-fcm"
@SFRohan , do you mean, I don't need to use the "react-native-push-notification" library?
@zootopia106 , i use firebase in my project. No need for react-native-push-notification. With firebase, you can also test messages/PN's from their console on their website.
import FCM, {
FCMEvent,
RemoteNotificationResult,
WillPresentNotificationResult,
NotificationType,
} from "react-native-fcm"
make sense what you mean, Thanks, @SFRohan
You're welcome @zootopia106 Cheers.
I'm looking for a working solution for local notifications. Anyone found a way to make them working ?
For anyone who came across this thread, someone found a solution for this problem on a separate thread in this project.
Fix for foreground notifications on iOS
Enjoy <3
I have already tried this solution, but it doesn't work for me.
What is your JavaScript code please?
@amitassaraf Thank you!
@SFRohan where will you write the FCM.on method. either in root file or else where ever we required in our app. if it is written in route js file will the fcm.on be call when entering from background. What I'm thinking is it wont call when the app came from background because route js file(App.js) file will be called only when you launch the application. correct me if i'm wrong beacuse i'm new to reactnative
Same issue on Android