Commit 669d2630 authored by Libin Lu's avatar Libin Lu

removeDeliveredNotifications

parent d60b36d5
......@@ -253,24 +253,13 @@ public class FIRLocalMessagingHelper {
}
public void cancelLocalNotification(String notificationId) {
NotificationManager notificationManager =
(NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(notificationId.hashCode());
cancelAlarm(notificationId);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove(notificationId);
editor.apply();
}
public void cancelAllLocalNotifications() {
NotificationManager notificationManager =
(NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
java.util.Map<String, ?> keyMap = sharedPreferences.getAll();
SharedPreferences.Editor editor = sharedPreferences.edit();
for(java.util.Map.Entry<String, ?> entry:keyMap.entrySet()){
......@@ -280,6 +269,16 @@ public class FIRLocalMessagingHelper {
editor.apply();
}
public void removeDeliveredNotification(String notificationId){
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(notificationId.hashCode());
}
public void removeAllDeliveredNotifications(){
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
}
public void cancelAlarm(String notificationId) {
Intent notificationIntent = new Intent(mContext, FIRLocalMessagingPublisher.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, notificationId.hashCode(), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
......
......@@ -95,6 +95,16 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
mFIRLocalMessagingHelper.cancelAllLocalNotifications();
}
@ReactMethod
public void removeDeliveredNotification(String notificationID) {
mFIRLocalMessagingHelper.removeDeliveredNotification(notificationID);
}
@ReactMethod
public void removeAllDeliveredNotifications(){
mFIRLocalMessagingHelper.removeAllDeliveredNotifications();
}
@ReactMethod
public void subscribeToTopic(String topic){
FirebaseMessaging.getInstance().subscribeToTopic(topic);
......
......@@ -39,6 +39,9 @@ FCM.getScheduledLocalNotifications = function() {
};
FCM.cancelLocalNotification = (notificationID) => {
if(!notificationID){
return;
}
RNFIRMessaging.cancelLocalNotification(notificationID);
};
......@@ -46,6 +49,17 @@ FCM.cancelAllLocalNotifications = () => {
RNFIRMessaging.cancelAllLocalNotifications();
};
FCM.removeDeliveredNotification = (notificationID) => {
if(!notificationID){
return;
}
RNFIRMessaging.removeDeliveredNotification(notificationID);
}
FCM.removeAllDeliveredNotifications = () => {
RNFIRMessaging.removeAllDeliveredNotifications();
}
FCM.setBadgeNumber = (number) => {
RNFIRMessaging.setBadgeNumber(number);
}
......
......@@ -276,13 +276,27 @@ RCT_EXPORT_METHOD(scheduleLocalNotification:(id)data resolver:(RCTPromiseResolve
}
}
RCT_EXPORT_METHOD(removeDeliveredNotifications:(NSString*) notificationId)
{
if([UNUserNotificationCenter currentNotificationCenter] != nil){
[[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:@[notificationId]];
}
}
RCT_EXPORT_METHOD(removeAllDeliveredNotifications)
{
if([UNUserNotificationCenter currentNotificationCenter] != nil){
[[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];
} else {
[RCTSharedApplication() setApplicationIconBadgeNumber: 0];
}
}
RCT_EXPORT_METHOD(cancelAllLocalNotifications)
{
if([UNUserNotificationCenter currentNotificationCenter] != nil){
[[UNUserNotificationCenter currentNotificationCenter] removeAllPendingNotificationRequests];
[[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];
} else {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
[RCTSharedApplication() cancelAllLocalNotifications];
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment