Local Notifications (Capacitor/React): Do not trigger on iOS

Hey all,

I’m trying to implement Local Notifications on iOS. They do not seem to trigger at all.

React.useEffect(() => {
    LocalNotifications.schedule({
      notifications: [
        {
          title: "Test Title",
          body: "Test Body",
          id: id: Math.floor(Math.random() * 6000000),
          schedule: {
            at: new Date(Date.now() + 1000 * 5), // in 5 secs
            repeats: false
          }
        }
      ]
    });
    
  }, [])

Do you have any idea?

The console.log seems to be fine, no error messages.

Welcome to the community!

Are you requesting permission first with requestPermissions?

Basically something like this:

if (await LocalNotifications.requestPermissions()).display === 'granted') {
  // continue with stuff
}

Do note that you only want to request permission once. After that, you use checkPermissions. The flow that I use is that once the user installs the app, I display a modal asking them to give permissions while explaining why they would want to.

Then on the screen where they can set notifications, I check if they granted permission. If they did, I let them continue. If they explicitly denied, I display a message saying that they didn’t grant permission and need to within the app settings in iOS in order to set a notification. if they didn’t accept or deny, then I show the request permission modal again (PermissionState = prompt).

1 Like