【问题标题】:iOS push notification banner clear action button [duplicate]iOS推送通知横幅清除操作按钮[重复]
【发布时间】:2018-12-12 10:55:41
【问题描述】:

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

图片已附加,我想在用户点击此明确操作时触发任何想法???

{
   “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()
}

【问题讨论】:

    标签: ios swift unnotificationserviceextension


    【解决方案1】:

    来自docs关于actionIdentifier

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

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

    代替

    "ACCEPT_ACTION"
    

    使用

    UNNotificationDefaultActionIdentifier
    

    而不是

    "DECLINE_ACTION"
    

    使用

    UNNotificationDismissActionIdentifier
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-07
      • 1970-01-01
      • 2012-06-16
      • 2023-03-10
      相关资源
      最近更新 更多