react-native-push-notification icon indicating copy to clipboard operation
react-native-push-notification copied to clipboard

iOS local notification in the foreground mode doesn't show notification!

Open thegrucoder opened this issue 8 years ago • 24 comments

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

thegrucoder avatar Dec 25 '17 07:12 thegrucoder

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

damir-sirola avatar Jan 08 '18 12:01 damir-sirola

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.

thegrucoder avatar Jan 08 '18 12:01 thegrucoder

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?

hszeto avatar Jan 17 '18 09:01 hszeto

I have the same issue I'm trying to figure it out.

hugoh59 avatar Jan 18 '18 14:01 hugoh59

Anyone able to solve this issue? Having similar issue..

bwoodlt avatar Jan 22 '18 06:01 bwoodlt

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

joaom182 avatar Mar 21 '18 17:03 joaom182

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

SFRohan avatar Jul 18 '18 07:07 SFRohan

local_notification: true

has been added to avoid infinite loop of messages on iOS device.

SFRohan avatar Jul 18 '18 07:07 SFRohan

Thanks for your help , @SFRohan If so, do i have to integrate FCM apart from this library?

thegrucoder avatar Jul 18 '18 07:07 thegrucoder

Hi @zootopia106 , yes you would need to integrate FCM for this from "react-native-fcm"

SFRohan avatar Jul 18 '18 07:07 SFRohan

@SFRohan , do you mean, I don't need to use the "react-native-push-notification" library?

thegrucoder avatar Jul 18 '18 07:07 thegrucoder

@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"

SFRohan avatar Jul 18 '18 07:07 SFRohan

make sense what you mean, Thanks, @SFRohan

thegrucoder avatar Jul 18 '18 07:07 thegrucoder

You're welcome @zootopia106 Cheers.

SFRohan avatar Jul 18 '18 07:07 SFRohan

I'm looking for a working solution for local notifications. Anyone found a way to make them working ?

zedtux avatar Oct 12 '18 14:10 zedtux

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

amitassaraf avatar Nov 06 '18 21:11 amitassaraf

I have already tried this solution, but it doesn't work for me.

What is your JavaScript code please?

zedtux avatar Nov 07 '18 07:11 zedtux

@amitassaraf Thank you!

HanKyongIl avatar Nov 15 '18 16:11 HanKyongIl

@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

saikiranoptisol avatar Feb 23 '19 06:02 saikiranoptisol

Same issue on Android

joaom182 avatar May 30 '19 14:05 joaom182