Share the post

Hello All, In last topic we had disusssed Firebase Push Notification in Ionic application. We already know that the importance of notification in our mobile application is how much important is! Now, After trying the firebase push notification we move ahead & integrate the local notification in our mobile application. So, In this topic we will discuss Local notification integration in our ionic application with the help of example.

Why Local Notification is required?

Now, Before we start integration its important to know Why do we want to integrate the local notification if we already have firebase push notification integrated. Because, If we want to show notification to the user which is necessary to show them even if they are not connected with internet. So, In short If you want to show fireabase push notification then user must be connected with internet, but it’s exactly opposite in case of local notification. Below are the main focus points which are important in case of Local notification.

  • serverless notification
  • allow to display notification on device
  • can schedule the notification as per our application needs
  • by showing notification we can kept user to busy with our application.

Steps to integrate local notification in Ionic application

Step 1 : Create a new project using following command

ionic start <appname> <template>

Step 2 : Install the dependencies using following commands

npm install @capacitor/local-notifications
npx cap sync

Step 3 : Create a common service to show a local notification

npm ionic g service local-notification
import { LocalNotifications } from '@capacitor/local-notifications';



async showLocalNotification(id : number, title : string, text : string){

    title : title,
    body : text,
    id : id

Add this dependency in app.module.ts

Step 4 : Add a button to show notification

<ion-button expand="block" (click)="sendLocalNotification()">
Send Local notification

Step 5 : Add below code to your ts file

import { LocalNotificationService } from ../local-notification.service
constructor ( private localNotification : LocalNotificationService ) {}

sendLocalNotification () {
  this.localNotification.showLocalNotification ( " TITLE ", " TEST NOTIFICATION " , 1 );

Leave a Comment