1

I'm currently facing problem while viewing action buttons on time-interval notification on iOS 10. I have created two UNNotificationAction objects 'OK' & 'Cancel' added as notification category.

I'm getting notification on simulator without any action button. Below is my code.

let ok = UNNotificationAction(identifier: "OKIdentifier",
                                      title: "OK", options: [])

let cancel = UNNotificationAction(identifier: "CancelIdentifier",
                                  title: "Cancel",
                                  options: [])

let category = UNNotificationCategory(identifier: "message",
                                      actions: [ok, cancel],
                                      minimalActions: [ok, cancel],
                                      intentIdentifiers: [],
                                      options: [])

UNUserNotificationCenter.current().setNotificationCategories([category!])

let content = UNMutableNotificationContent()
content.title = contentTitle
content.subtitle = contentSubtitle
content.body = contentBody

let model: TimeIntervalNotificationModel = notificationsModel as!  TimeIntervalNotificationModel

trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: model.timeInterval!, repeats: notificationsModel.repeats) as UNTimeIntervalNotificationTrigger

let request = UNNotificationRequest(identifier:requestIdentifier, content: content, trigger: trigger)

UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().add(request){(error) in
                if (error != nil){
                    //handle here
         print("Error: Adding notification failed:\(error?.description)")

         self.delegate?.didFailToAddNotification(error: error!)
                }
            }
Cœur
  • 37,241
  • 25
  • 195
  • 267
niks
  • 544
  • 11
  • 28

1 Answers1

11

Fixed the problem. Forgot to set category identifier property of Notification content.

content.categoryIdentifier = "message"

Definition:

The identifier of the app-defined category object Specify a category identifier to create an actionable notifications. The identifier must belong to a UNNotificationCategory object that you previously registered with your app. When the notification is delivered to the user, the system adds the actions defined in that category object to the notification interface as appropriate.

niks
  • 544
  • 11
  • 28