Local Notifications

Material for Platform Based Development

Local Notifications

In this guide, we will learn how to use the Local Notifications plugin with Capacitor.

You can use Ionic Live Reload feature for testing your plugins in a mobile device.

Goal

Send a notification at a specific time. Let's say we want to send a notification a few seconds after a new member is added.

Capacitor Plugin

npm install @capacitor/local-notifications --save

In main.ts:

import { LocalNotifications } from '@capacitor/local-notifications';

LocalNotifications.requestPermissions()

In member-create.page.ts:

LocalNotifications.schedule({
  notifications: [
    {
      id: new Date().getTime(),
      title: "New member",
      body: `${values.fullname} is a new member. Don't forget to welcome him`,
      schedule: {
        at: new Date(new Date().getTime() + 10000)
      }
    }
  ]
})