Send Ionic 3 Local Notification every day at a specific time

前端 未结 4 818
慢半拍i
慢半拍i 2021-01-23 07:05

I have added the Ionic 3 local notification plugin to my project using these commands:

ionic cordova plugin add cordova-plugin-local-notification
npm install --s         


        
4条回答
  •  孤街浪徒
    2021-01-23 07:47

    In order to make a daily repeated notification, you need to use an every:"day" (or interval in minutes: every: 24*60) and a firstAt property with the date when the notification will be triggered for the first time. Try this code

    let year = new Date().getFullYear();
    let month = new Date().getMonth();
    let day = new Date().getDate();
    
    let time1 = new Date(year, month, day, 10, 00, 0, 0);
    let time2 = new Date(year, month, day, 12, 00, 0, 0);
    
    this.localNotifications.schedule([
      {
        id: 1,
        title: 'My first notification',
        text: 'First notification test one',
        firstAt: new Date(time1),
        every: 24*60,
        data: {"id": 1, "name": "Mr. A"}
      },
      {
        id: 2,
        title: 'My Second notification',
        text: 'Second notification on 12 pm',
        firstAt: new Date(time2),
        every: 24*60,
        data: {"id": 2, "name": "Mr. B"}
      }
    ]);
    

提交回复
热议问题