0

i want to do something when user clear notification from home screen is it possible to get trigger when user tap on clear button on push notification banner, i ended up with adding custom button on view but thats not feasible.

enter image description here

image is attached i want trigger when user tap on this clear action any idea ???

{
   “aps” : {
      “category” : “MEETING_INVITATION”
      “alert” : {
         “title” : “Weekly Staff Meeting”
         “body” : “Every Tuesday at 2pm”
      },
   },
   “MEETING_ID” : “123456789”,
   “USER_ID” : “ABCD1234”

} 

i have done this but its adding button on view like popup

func userNotificationCenter(_ center: UNUserNotificationCenter,
       didReceive response: UNNotificationResponse,
       withCompletionHandler completionHandler: 
         @escaping () -> Void) {

   // Get the meeting ID from the original notification.
   let userInfo = response.notification.request.content.userInfo
   let meetingID = userInfo["MEETING_ID"] as! String
   let userID = userInfo["USER_ID"] as! String

   // Perform the task associated with the action.
   switch response.actionIdentifier {
   case "ACCEPT_ACTION":
      sharedMeetingManager.acceptMeeting(user: userID, 
                                    meetingID: meetingID)
      break

   case "DECLINE_ACTION":
      sharedMeetingManager.declineMeeting(user: userID, 
                                     meetingID: meetingID)
      break

   // Handle other actions…

   default:
      break
   }

   // Always call the completion handler when done.    
   completionHandler()
}
junaid
  • 193
  • 1
  • 16

1 Answers1

1

From docs about actionIdentifier:

This parameter may contain one the identifier of one of your UNNotificationAction objects or it may contain a system-defined identifier. The system defined identifiers are UNNotificationDefaultActionIdentifier and UNNotificationDismissActionIdentifier, which indicate that the user opened the app or dismissed the notification without any further actions.

So you don’t have to use your own identifiers, use system’s.

Instead of

"ACCEPT_ACTION"

use

UNNotificationDefaultActionIdentifier

and instead of

"DECLINE_ACTION"

use

UNNotificationDismissActionIdentifier
Robert Dresler
  • 10,580
  • 2
  • 22
  • 40