预期未触发通知

时间:2019-09-09 19:23:45

标签: android angular cordova notifications ionic4

我正在使用离子网站上推荐使用的cordova插件在我的应用程序中实现cordova-plugin-local-notifications通知。

当我使用这种格式安排通知时

  {
      title: 'Appointment!',
      text: 'You have an appointment at ' + e.startTime.toTimeString(),
      data: {
        eventid: e.id,
        event: e
      },
      trigger: { at: new Date(e.startTime) },
      foreground: true, // Show the notification while app is open
      priority: 1
    }

当我告诉我使用当前时间或过去时间时,该通知就会触发。如果我将其设置为将来一分钟,则该通知将永远不会出现。

使用android studio进行调试,我可以看到它设置了事件

2019-09-09 16:10:05.480 10287-10287/weusthem.myexp D/CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.core.fireEvent("add",{"title":"Appointment!","text":"You have an appointment at 16:11:00 GMT-0300 (Atlantic Daylight Time)","data":"{\"eventid\":\"1568056205360Bob\",\"event\":{\"id\":\"1568056205360Bob\",\"title\":\"Bob\",\"startTime\":\"2019-09-09T19:11:00.409Z\",\"endTime\":\"2019-09-09T19:11:33.409Z\",\"allDay\":false,\"desc\":\"\",\"dateCreated\":\"2019-09-09T19:10:05.360Z\",\"provider\":{\"id\":\"Bob1567779696555\",\"name\":\"Bob\",\"jobTitle\":\"\",\"sees\":\"Both\",\"heardAboutFrom\":\"My Family Doctor\"}}}","trigger":{"at":1568056260409,"type":"calendar"},"foreground":true,"priority":1,"actions":[],"attachments":[],"autoClear":true,"defaults":0,"groupSummary":false,"id":0,"launch":true,"led":{"color":"#FFFFFF","on":500,"off":500},"lockscreen":true,"number":0,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"showWhen":true,"silent":false,"smallIcon":"res:\/\/icon","sound":true,"vibrate":true,"wakeup":true,"meta":{"plugin":"cordova-plugin-local-notification","version":"0.9-beta.2"}},{"event":"add","foreground":true,"queued":false,"notification":0}))

我应该可以看到警报火

2019-09-09 16:11:00.410 1365-2300/? V/AlarmManager: Triggering alarm #0: 1 when =1568056260409 package =weusthem.myexp operation =*alarm*:NOTIFICATION_ID0-2 flags =0x1

但是手机上没有任何通知。

知道我要去哪里哪里吗?

1 个答案:

答案 0 :(得分:0)

显然,您需要为每个通知分配一个ID,它不会自动为其分配。如果您未指定ID,则下一个没有ID的通知将覆盖该通知。非常烦人,因为自动分配ID会非常有用。我的通知被新通知覆盖。