-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Conversation
One point of possible confusion I see is the fact that the handling of the new attribute doesn't define an independent top level behavior, but instead define a new "minor feature", parallel to the usual notification handling. In other terms, you mentioned this in the issue, but we need to make sure this is explicit and clean in the docs, at the very least:
Instead of calling this "a notification payload do clear the drawer", we should call it "a normal notification, that can also explicitly ask to clear the drawer before being handled". I hope I made myself clear, words are hard. |
I understand what you mean. I'll try and whip up something inteligible for the documentation when I have a bit of time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes but the PAYLOAD.md doc also has to be updated with the new payload information.
@@ -329,6 +330,12 @@ private void showNotificationIfPossible(Context context, Bundle extras) { | |||
Log.d(LOG_TAG, "title =[" + title + "]"); | |||
Log.d(LOG_TAG, "contentAvailable =[" + contentAvailable + "]"); | |||
Log.d(LOG_TAG, "forceStart =[" + forceStart + "]"); | |||
Log.d(LOG_TAG, "clearNotifications =[" + clearNotifications + "]"); | |||
|
|||
if ("true".equals(clearNotifications)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Users may send clearNotifications as a string or as a boolean so we should expect them to mess up and check string equality for "true" and if it is the boolean true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was unable to retrieve the value as a boolean even when sent with "clearAllNotifications": true
. Java claimed it was a string every time, so this is why I set it to a string.
Any ideas why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not without looking into it in more detail but I'd bet it is some kinda of screwy JSON serialization issue on Android.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made some of the changes but I'll leave this one for later.
src/ios/AppDelegate+notification.m
Outdated
@@ -107,6 +107,15 @@ - (void) application:(UIApplication *)application didReceiveRemoteNotification:( | |||
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { | |||
NSLog(@"didReceiveNotification with fetchCompletionHandler"); | |||
|
|||
id clearAllNotifications = [userInfo objectForKey:@"clearAllNotifications"]; | |||
if ([clearAllNotifications isKindOfClass:[NSString class]] && [clearAllNotifications isEqualToString:@"true"]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing as the Android comment. Should check string or boolean values.
if (([clearAllNotifications isKindOfClass:[NSString class]] && [clearAllNotifications isEqualToString:@"true"]) || [clearAllNotifications boolValue])
Superseded by #2521 |
This thread has been automatically locked. |
Added handling for a
"clearAllNotifications": "true"
key-value pair on iOS and Android which clears the notifications.Description
Simply added code which gets the value from the payload, and if it's "true", it executes code which removes notifications from the notification area.
Related Issue
#2371
Motivation and Context
It's a straight-forward way to clear time-sensitive notifications an app may have. Simply send the payload, and it's done.
How Has This Been Tested?
Android 6.0.1 and iOS 11.3.1
Notifications sent via Postman
Sent notifications to both platforms, both in background and force-closed. Then, sent the payload which clears the notififications.
Android
Background: Notifications all disappear.
Force-closed: Notifications all disappear.
iOS
Background: Notifications all disappear
Force-closed: Nothing happens. Doesn't seem to be able to run the code. Would love some help with this if you want.
iOS note : Why does the iOS code first increment the iconApplicationBadgeNumber and then clear it before removing the notifications?
Simply put, it just didn't work otherwise. If you know better, let me know.
Notification used to clear the pre-existing notifications:
In the case that you send a notification with a body and a title, and it also contains this payload (see what I mean below), first, the old notifications will be cleared, and then the new notification will be added. This will result in one remaining notification in the notification drawer.
Android:
iOS:
Screenshots (if appropriate):
N/A
Types of changes
Checklist: