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

时间:2015-07-07 00:17:56

标签: push-notification ionic-framework ionic

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

提前多多感谢

1 个答案:

答案 0 :(得分:1)

I did some digging as I too had this problem, and it looks like a bug in the Push Plugin. Basically they added the removal code to the pause event instead of the resume event.

You just have to change the code in src/android/com/plugin/gcm/PushPlugin.java

from:

@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;
}

to:

@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();
}

This will create a more standard behaviour, where the notifications will be removed on app resume (instead of on pause). Note though, I haven't fully tested the effects on the internal app messages yet, which may require more changes.