如何清除来自 Ionic Push 的推送通知?

How to clear push notification from Ionic Push?

当用户点击通知打开应用程序时,推送通知会被清除。但是,如果用户去打开应用程序,推送通知仍然存在。我怎样才能摆脱通知?我似乎无法在解决此问题的文档中找到任何地方。

非常感谢

我也遇到了这个问题,所以我做了一些挖掘,它看起来像是推送插件中的一个错误。基本上他们将删除代码添加到暂停事件而不是恢复事件。

您只需更改 src/android/com/plugin/gcm/PushPlugin.java

中的代码

来自:

@Override
public void onPause(boolean multitasking) {
    super.onPause(multitasking);
    gForeground = false;
    final NotificationManager notificationManager = (NotificationManager) cordova.getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
}

@Override
public void onResume(boolean multitasking) {
    super.onResume(multitasking);
    gForeground = true;
}

至:

@Override
public void onPause(boolean multitasking) {
    super.onPause(multitasking);
    gForeground = false;
}

@Override
public void onResume(boolean multitasking) {
    super.onResume(multitasking);
    gForeground = true;
    final NotificationManager notificationManager = (NotificationManager) cordova.getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancelAll();
}

这将创建一个更标准的行为,通知将在应用恢复时(而不是暂停时)被删除。不过请注意,我还没有完全测试对内部应用程序消息的影响,这可能需要更多更改。