cordova-plugin-local-notifications: Local notifications not working in ios

WARNING: IF YOU IGNORE THIS TEMPLATE, WE’LL IGNORE YOUR ISSUE. YOU MUST FILL THIS IN!

Provide a general summary of the issue.

Your Environment

  • Plugin version: 0.8.5
  • Platform: IOS
  • OS version: 11.1.2
  • Device manufacturer / model: Apple
  • Cordova version (cordova -v): 7.1.0
  • Cordova platform version (cordova platform ls): Installed platforms: android 6.2.2 ios 4.5.4
  • Plugin config
  • Ionic Version (if using Ionic) 2.0.0

Expected Behavior

When the app is in foreground, I want a local notification.

Actual Behavior

No notification arrives but as soon as I take my app in the background, the notification comes.

Steps to Reproduce

I’m using cordova-plugin-fcm for push notifications in case of background and app killed. In case of app in foreground, I’m scheduling local notification using the plugin. This is my code:

            FCMPlugin.onNotification((msg) => {
                this.notificationMsg = msg;
                if (msg.wasTapped) {
                 // code for app background and app killed
                }
                else {
                    LocalNotifications.schedule({
                            id: 1,
                            title: 'title',
                            text: 'text',
                        })
               }
            })

But no local notifications comes up in foreground. But as soon as I minimize the app, it comes. What’s the issue here? Anything to do with plugin version? Please help.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 2
  • Comments: 36 (8 by maintainers)

Most upvoted comments

Adding “foreground: true” solved this problem for me:

const notification = { id, title, text, silent: false, foreground: true };
this.notifications.schedule(notification);`

cordova-plugin-push is conflict with this plugin, change code below of cordova-plugin-push solved this problem. change

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
    NSLog( @"NotificationCenter Handle push from foreground" );
    // custom code to handle push while app is in the foreground
    PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
    pushHandler.notificationMessage = notification.request.content.userInfo;
    pushHandler.isInline = YES;
    [pushHandler notificationReceived];

    completionHandler(UNNotificationPresentationOptionNone);
}

to

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
    UNNotificationRequest* toast = notification.request;
    if ([toast.trigger isKindOfClass:UNPushNotificationTrigger.class]) // add this line
    {
        NSLog( @"NotificationCenter Handle push from foreground" );
        // custom code to handle push while app is in the foreground
        PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
        pushHandler.notificationMessage = notification.request.content.userInfo;
        pushHandler.isInline = YES;
        [pushHandler notificationReceived];

        completionHandler(UNNotificationPresentationOptionNone);
    }
}

Local notification for ios is working now