cordova-plugin-local-notifications icon indicating copy to clipboard operation
cordova-plugin-local-notifications copied to clipboard

local notification not worked when app is open (ios)

Open AhmedRaafat13 opened this issue 6 years ago • 16 comments

local notification not worked when app is open

Plugin version: 0.9.0-beta.3 Platform: ios OS version: 11.1.2 Device manufacturer / model: ipad Cordova version (cordova -v): 7.1.0 Cordova platform version (cordova platform ls): 6.3.0* Plugin config

Expected Behavior LocalNotification not worked in ios when app is open

Tell us what happens instead LocalNotification not worked in ios when app is open but in background and when app is closed it works

AhmedRaafat13 avatar Oct 29 '18 11:10 AhmedRaafat13

please answer me

AhmedRaafat13 avatar Nov 01 '18 08:11 AhmedRaafat13

Hello,

I have the same issue. The notification is received but it doesn't show in the notification center, also no sound.

The problem is that FCM Plugin "onNotification" event is being triggered when a local notification is scheduled. The result is an infinite loop! Here is the sequence: 1- FCM plugin receives a notification in foreground 2- A local notification is scheduled 3- FCM onNotification is triggered again 4- A local notification is scheduled, and it keeps going with that sequence...

What's really weird is that it works fine on Android!

image

salomari avatar Nov 02 '18 09:11 salomari

Did you try the foreground and/or silent options?

AlexanderKoehn avatar Nov 03 '18 15:11 AlexanderKoehn

Did you try the foreground and/or silent options?

Hello Alexander,

As you see in the screenshot, I'm setting foreground to true. The silent option is not what I want because I believe it will not display a banner or pop up a notification in the notification center.

Any suggestions?

Thanks!

salomari avatar Nov 04 '18 06:11 salomari

Hello Alexander, it is not working in foreground but is working in background and when app is closed

AhmedRaafat13 avatar Nov 06 '18 09:11 AhmedRaafat13

Hmm I've only used it successfully with trigger: { at: someDate }

AlexanderKoehn avatar Nov 08 '18 20:11 AlexanderKoehn

Hmm I've only used it successfully with trigger: { at: someDate }

Can I set the date to current data/time? I want to trigger the notification as soon as I receive a push notification when the app is in foreground.

salomari avatar Nov 08 '18 20:11 salomari

doesnt work with fcm, foreground notification send by local notification are captured by ionic fcm onNotification event

weequan93 avatar Dec 06 '18 06:12 weequan93

the same problem as salomari

JuanCarlosSC avatar Feb 01 '19 00:02 JuanCarlosSC

the same problem

mamzellejuu avatar Feb 04 '19 19:02 mamzellejuu

The same problem, how to fix it?

shikelong avatar Mar 01 '19 07:03 shikelong

Facing the same problem with the latest release on ios 12.2, but was working earlier don't know why.

maxgaurav avatar Jul 03 '19 12:07 maxgaurav

@maxgaurav were u able to fix it? in the apple doc it is mentioned that :

This method (UNUserNotificationCenter.current().add) schedules local notifications only; you cannot use it to schedule the delivery of remote notifications. Upon calling this method, the system begins tracking the trigger conditions associated with your request. When the trigger condition is met, the system delivers your notification. If the request does not contain a UNNotificationTrigger object, the notification is delivered right away.

does this effect?

ghost avatar Aug 05 '19 08:08 ghost

I fixed with a dirty hack. I am maintaining an array of received notification ids and I only fire local notification if one is not already fired for that id.

if (!this.notificationIds.find(s => s === id)) {
                        const newId = this.getRandomInt(10000, 99999999);

                        console.log('LocalNotif', newId, title, body);

                        this.localNotification.schedule({
                            id: newId,
                            title,
                            text: body,
                            foreground: true,
                            icon: '../../../assets/icon/nav-bar-icons/inbox.svg',
                        });

                        this.notificationIds.push(newId);

                        this.localNotification.on('click').subscribe(data => {
                            this.router.navigateByUrl('mobile/messages');
                        });
}

kush-prof avatar Aug 02 '20 15:08 kush-prof

After this the infinite loop problem was gone but I started facing another problem that when my app is in foreground the onNotification callback is not getting more than once. Any help on this?

kush-prof avatar Aug 02 '20 15:08 kush-prof

@kush-prof Thanks for sharing your hack, I managed to use it with a few minor changes. I haven't had any problems with onNotification being triggered only once, hope you solved it at the end.

adammurin avatar Aug 16 '21 21:08 adammurin