local notification with Scheduler in Ionic 4 does not work on sdk 28+ when using Trigger

Asked

Viewed 39 times

0

Works

 this.localNotifications.schedule({
      id: 1,
      summary: "Amanhã  3444" ,
      text: 'teste local notification ',
      smallIcon: "res://icone_in",

      title: "aaaa 3",

      led: 'FF0000',
      sound: null
   });

doesn’t work

 this.localNotifications.schedule({
      id: 1,
      summary: "Amanhã  3444" ,
      text: 'teste local notification ',
      smallIcon: "res://icone_in",

      title: "aaaa 3",
      trigger: {at: new Date(new Date().getTime() + 10000)},
      led: 'FF0000',
      sound: null
   });

I’m using

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

Thank you

  • You know when time is new Date(new Date().getTime() + 10000)? By the account, it would be 10 seconds in the future, you waited the 10 seconds with the app open?

  • Yes I left well more I did tests when I add no time

1 answer

0

You tried to import as follows?

import {LocalNotifications} from "@ionic-native/local-notifications/ngx";

I am currently using the [email protected] version

It is also necessary to check whether the user has given permission

this.localNotifications.hasPermission().then(permission => {
    console.log(`hasPermission: ${permission}`);
    if (permission) {
        this.localNotifications.schedule({
            id: 1,
            text: notification.title,
            data: notification
        });
    } else {
        this.localNotifications.requestPermission().then(value => {
            console.log(`requestPermission: ${value}`);
            if (value) {
                this.localNotifications.schedule({
                    id: 1,
                    text: notification.title,
                    data: notification
                });
            } else {
                console.log("Sem permissão para notificações locais");
            }
        });
    }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.