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

removeDeliveredNotifications

parent d60b36d5
...@@ -253,24 +253,13 @@ public class FIRLocalMessagingHelper { ...@@ -253,24 +253,13 @@ public class FIRLocalMessagingHelper {
} }
public void cancelLocalNotification(String notificationId) { public void cancelLocalNotification(String notificationId) {
NotificationManager notificationManager =
(NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(notificationId.hashCode());
cancelAlarm(notificationId); cancelAlarm(notificationId);
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
editor.remove(notificationId); editor.remove(notificationId);
editor.apply(); editor.apply();
} }
public void cancelAllLocalNotifications() { public void cancelAllLocalNotifications() {
NotificationManager notificationManager =
(NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancelAll();
java.util.Map<String, ?> keyMap = sharedPreferences.getAll(); java.util.Map<String, ?> keyMap = sharedPreferences.getAll();
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
for(java.util.Map.Entry<String, ?> entry:keyMap.entrySet()){ for(java.util.Map.Entry<String, ?> entry:keyMap.entrySet()){
...@@ -280,6 +269,16 @@ public class FIRLocalMessagingHelper { ...@@ -280,6 +269,16 @@ public class FIRLocalMessagingHelper {
editor.apply(); 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) { public void cancelAlarm(String notificationId) {
Intent notificationIntent = new Intent(mContext, FIRLocalMessagingPublisher.class); Intent notificationIntent = new Intent(mContext, FIRLocalMessagingPublisher.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, notificationId.hashCode(), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, notificationId.hashCode(), notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
......
...@@ -95,6 +95,16 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li ...@@ -95,6 +95,16 @@ public class FIRMessagingModule extends ReactContextBaseJavaModule implements Li
mFIRLocalMessagingHelper.cancelAllLocalNotifications(); mFIRLocalMessagingHelper.cancelAllLocalNotifications();
} }
@ReactMethod
public void removeDeliveredNotification(String notificationID) {
mFIRLocalMessagingHelper.removeDeliveredNotification(notificationID);
}
@ReactMethod
public void removeAllDeliveredNotifications(){
mFIRLocalMessagingHelper.removeAllDeliveredNotifications();
}
@ReactMethod @ReactMethod
public void subscribeToTopic(String topic){ public void subscribeToTopic(String topic){
FirebaseMessaging.getInstance().subscribeToTopic(topic); FirebaseMessaging.getInstance().subscribeToTopic(topic);
......
...@@ -39,13 +39,27 @@ FCM.getScheduledLocalNotifications = function() { ...@@ -39,13 +39,27 @@ FCM.getScheduledLocalNotifications = function() {
}; };
FCM.cancelLocalNotification = (notificationID) => { FCM.cancelLocalNotification = (notificationID) => {
RNFIRMessaging.cancelLocalNotification(notificationID); if(!notificationID){
return;
}
RNFIRMessaging.cancelLocalNotification(notificationID);
}; };
FCM.cancelAllLocalNotifications = () => { FCM.cancelAllLocalNotifications = () => {
RNFIRMessaging.cancelAllLocalNotifications(); RNFIRMessaging.cancelAllLocalNotifications();
}; };
FCM.removeDeliveredNotification = (notificationID) => {
if(!notificationID){
return;
}
RNFIRMessaging.removeDeliveredNotification(notificationID);
}
FCM.removeAllDeliveredNotifications = () => {
RNFIRMessaging.removeAllDeliveredNotifications();
}
FCM.setBadgeNumber = (number) => { FCM.setBadgeNumber = (number) => {
RNFIRMessaging.setBadgeNumber(number); RNFIRMessaging.setBadgeNumber(number);
} }
......
...@@ -276,13 +276,27 @@ RCT_EXPORT_METHOD(scheduleLocalNotification:(id)data resolver:(RCTPromiseResolve ...@@ -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) RCT_EXPORT_METHOD(cancelAllLocalNotifications)
{ {
if([UNUserNotificationCenter currentNotificationCenter] != nil){ if([UNUserNotificationCenter currentNotificationCenter] != nil){
[[UNUserNotificationCenter currentNotificationCenter] removeAllPendingNotificationRequests]; [[UNUserNotificationCenter currentNotificationCenter] removeAllPendingNotificationRequests];
[[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];
} else { } else {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
[RCTSharedApplication() cancelAllLocalNotifications]; [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