Praful Kadam
Praful Kadam

Reputation: 392

ionic react local notifications with capacitor not working

I am trying to implement local notifications using capacitor.

first I installed plugin using below commands,

npm install @ionic-native/local-notifications
npm install cordova-plugin-local-notification

Then in my .js file, I did add below code

import { Plugins } from '@capacitor/core';

And

scheduleNotification = () => {
 Plugins.LocalNotifications.schedule({
    notifications: [
      {
        title: "Title",
        body: "Body",
        id: 1,
        schedule: { at: new Date(Date.now() + 1000 * 5) },
        sound: null,
        attachments: null,
        actionTypeId: "",
        extra: null
      }
    ]
  });
console.log('scheduled notifications');

}

I tried everything, but I can't see any local notification on my iPhone 6s running iOS 12. When I check Xcode logs, I can see Scheduled notification with id 1.

cordova-plugin-badge (0.8.8)
cordova-plugin-device (2.0.3)
cordova-plugin-local-notification (0.9.0-beta.2)

Upvotes: 5

Views: 3612

Answers (3)

Nicolas Briand
Nicolas Briand

Reputation: 21

I had the same issue, I set my notification id with an UUID but it did not work. I solved it in setting my notification id with new Date().getTime().

Upvotes: 1

Kaushik Parmar
Kaushik Parmar

Reputation: 1

It was issue regarding id pass in your result.

    PushNotifications.addListener('pushNotificationReceived',
      async (notification: any) => {
        console.log(notification);
        const notifs = await LocalNotifications.schedule({
          notifications: [
            {
              title: notification.title,
              body: notification.body,
              id: new Date().getTime(),
              schedule: { at: new Date(Date.now() + 1000 * 5) },
              sound: this.platform.is("android")
                ? "file://sound.mp3"
                : "file://beep.caf",
              attachments: null,
              actionTypeId: "",
              extra: notification
            }
          ]
        });
      }
    );

Upvotes: 0

Alwani Anis
Alwani Anis

Reputation: 258

For the ios, I think, it is not supported yet.

For android, try to request permission.

Upvotes: -1

Related Questions