【问题标题】:Ionic 3/4 - Daily Local Notifications not workingIonic 3/4 - 每日本地通知不起作用
【发布时间】:2018-10-26 19:30:49
【问题描述】:

本地通知无法正常工作(尝试使用 ionic 3 和 4)。 用户可以在应用程序中设置时间并打开或关闭通知。 使用以下代码时,我总是在上午 01:00 收到通知,尽管我已将其设置为 17:30 或其他时间。 我尝试了很多变体,这是最后一个:

const time = setsub.task_reminder_time.split(':');
    const now = new Date();
    console.log('now is', now);
    const pushDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), +time[0], +time[1], 0);
    const options = {
      id: 1,
      title: 'Time to plan your day!',
      text: `Hey you! It's time to get productive by planning your day!\nTap here to open DoDay! ????`,
      trigger: { firstAt: pushDate, every: ELocalNotificationTriggerUnit.DAY }
    };
    if (setsub.task_reminder) {
      this.notification.requestPermission();
      this.notification.schedule(options);
    } else {
      this.notification.clearAll();
    }

time 只是一个包含通知时间的字符串,单位为 HH:mm 我正在使用 iOS 设备进行测试。

【问题讨论】:

    标签: ionic-framework notifications ionic3 uilocalnotification ionic4


    【解决方案1】:

    所以我自己找到了解决方案。这是 LocalNotifications 包的类型文件中的错误。

    选项的正确用法如下所示:

        {
          id: 1,
          title: 'Notification Title',
          text: 'Your notification text',
          foreground: true,
          trigger: {
            every: {
              hour: 8,
              minute: 15
            }
          }
        }
    

    只需进入您的 node_modules/@ionic-native/local-notifications 找到 index.d.ts 并找到显示 every?: ELocalNotificationTriggerUnit 的行并将其更改为 every?: any; 现在它应该可以正常工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多