Local notifications don't work under xCode simulation (works with android)

Hey Friends,

The local notifications from capacitor are working fine on Android, but don’t show up at all with the iOS simulation under xCode. There is no error message showing up in the xCode Console.

My notification entries looks like this:

notificationEntry = {
            id: dateInMS,
            title: `Leerung am ${dt.toLocaleString()}`,
            body: `${wasteTypesDisplayed}`,
            schedule: {
              at: alarmDateJS,
              allowWhileIdle: true,
            },
            foreground: true,
            smallIcon: 'ic_stat_tonne',
          }

Any help is appreciated.
Thanks a lot :slight_smile:

I could be mistaken, but I’m not sure if notifications (local or push) work in the iOS sim. Have you tried on a real device?

I think only the push notifications are not working with xCode. This dude is running a local notification on xCode: iOS Local Notification Tutorial - YouTube

You are correct! So I tested this out in a sample app and it worked well for me

  async ionViewDidEnter() {
    try {
      await LocalNotifications.requestPermissions();
    } catch (e) {
      console.log('there was an err', e);
    }
  }
  async scheduleNotification() {
    await LocalNotifications.schedule({
      notifications: [
        {
          title: 'My Notification',
          body: 'Testing if notifications work',
          id: Math.floor(Math.random() * 10),
          schedule: { at: new Date(Date.now() + 1000 * 5) },
        },
      ],
    });
  }

I do notice that the value for at is odd. Can you try this sample code I’ve provided? It should schedule a notification for 5seconds later.

1 Like

requestPermissions()

was missing on my App. Seems like it’s necessary for iOS.
Thanks a lot :slight_smile: