0

当用户从主屏幕清除通知时,我想做一些事情,当用户点击推送通知横幅上的清除按钮时,是否有可能触发,我最终在视图上添加了自定义按钮,但这是不可行的。

在此处输入图像描述

附加图像我想在用户点击这个明确的动作时触发任何想法???

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

} 

我已经这样做了,但它在视图上添加按钮,如弹出窗口

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()
}
4

1 回答 1

1

来自关于的文档actionIdentifier

此参数可能包含一个您的 UNNotificationAction 对象的标识符,或者它可能包含系统定义的标识符。系统定义的标识符是UNNotificationDefaultActionIdentifierUNNotificationDismissActionIdentifier,它们表示用户打开了应用程序或关闭了通知而没有任何进一步的操作。

所以你不必使用自己的标识符,使用系统的。

代替

"ACCEPT_ACTION"

利用

UNNotificationDefaultActionIdentifier

而不是

"DECLINE_ACTION"

利用

UNNotificationDismissActionIdentifier
于 2018-12-12T11:03:13.923 回答