本地通知在Android设备中持续触发一分钟

我正在使用插件在ionic 2应用程序中处理本地通知-


ionic cordova plugin add cordova-plugin-local-notification

npm install @ionic-native/local-notifications

该通知在ios设备中运行得非常好,但是对于android来说却显示出意外的行为。


异常行为- 在设定的时间重复同一天的通知。


当前行为 -通知持续一分钟。


我的要求是在每周的特定日期重复由用户设置的本地通知,该通知也应在用户设置的同一天和同一时间重复。


这是我的代码段-


makeLocalNotificationOn(mainDayNotifyObj, index) {

    let currentDate = new Date();

    let currentDay = currentDate.getDay(); // Sunday = 0, Monday = 1, etc.


    let indexOfDay;


    for (let i = 0; i < this.remainderDaysArray.length; i++) {

        if (mainDayNotifyObj.dayName == this.remainderDaysArray[i]) {

            indexOfDay = i;

            break;

        }

    }


    let setTime = mainDayNotifyObj.time.split(":");

    let hours = parseInt(setTime[0]);

    let minutes = parseInt(setTime[1]);



    let firstNotificationTime = new Date();

    let dayDifference = indexOfDay - currentDay;


    if (dayDifference < 0) {

        dayDifference = dayDifference + 7; // for cases where the day is in the following week

    }


    firstNotificationTime.setHours(firstNotificationTime.getHours() + (24 * (dayDifference)));

    firstNotificationTime.setHours(hours);

    firstNotificationTime.setMinutes(minutes);


    let weekDay = firstNotificationTime.getDay();


       let remainderObj = {

            id: index,

            title: 'Hello',

            text: 'Its time',

            foreground: true,

            trigger: {every: {weekday: weekDay, hour: hours, minute: minutes},firstAt: firstNotificationTime}

        };


    this.notificationArray.push(remainderObj);


    this.platform.ready().then(() => {

        this.localNotifications.schedule(this.notificationArray);


    });


}

任何帮助将不胜感激。谢谢


白衣染霜花
浏览 163回答 2
2回答

qq_花开花谢_0

我通过修改触发器对象的值解决了我的问题。我用来触发通知的其余对象有一些更改。这是代码段-remainderObj = {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id: index,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; title: 'Hello',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text: 'Its time',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; foreground: true,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; trigger{every{weekday:weekDay,hour:hours,minute:minutes},firstAt: firstNotificationTime,count:1}&nbsp; &nbsp; &nbsp; &nbsp; }该计数属性所做的工作时,计数= 1所触发的通知只有一次,在Android设备。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript