Min Khant Lu
Min Khant Lu

Reputation: 742

Adding UNNotificationAction to firebase FCM push notification in Swift 4

I am trying to add some custom action when FCM push notification. I tried adding these after when registering my notification.

UNUserNotificationCenter.current().delegate = self
        let acceptAction = UNNotificationAction(identifier: "ACCEPT_ACTION",
                                                title: "Accept",
                                                options: UNNotificationActionOptions(rawValue: 0))
        let declineAction = UNNotificationAction(identifier: "DECLINE_ACTION",
                                                 title: "Decline",
                                                 options: UNNotificationActionOptions(rawValue: 0))
        let center = UNUserNotificationCenter.current()
        if #available(iOS 11.0, *) {
            let meetingInviteCategory = UNNotificationCategory(identifier: "MEETING_INVITATION",
                                                               actions: [acceptAction, declineAction],
                                                               intentIdentifiers: [],
                                                               hiddenPreviewsBodyPlaceholder: "",
                                                               options: .customDismissAction)
            center.setNotificationCategories([meetingInviteCategory])
        }
        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]


        center.requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })

But unfortunately, the action is not still appearing. Is there anyway to achieve this? This is what I am trying to achieve.

example

My firebase FCM setup and all notification are working fine. I just can't add action to these notifications.

Upvotes: 1

Views: 667

Answers (1)

Min Khant Lu
Min Khant Lu

Reputation: 742

I got it. I just need to add click_action field in body of fcm/send. and set that click_action key to category identifier.

Upvotes: 2

Related Questions