Я использую действенные уведомления. Следующие данные поступают из бэкэнда:
- tificationId (String)
- заголовок уведомления, тело
- Каждый раз разные названия для 2 кнопок действий
Итак, я регистрирую и UNNotificationCategory, и categoryIdentifier (для UNMutableNotificationContent) с уникальным ID-идентификатором.
Постановка проблемы : - Определенно, все входящие уведомления всплывают со своими действиями уведомления. но когда я проверяю кнопки действий этих уведомлений внутри NotificationCenter . Только последнее уведомление, показывающее его кнопки действий и другие, отображаемые без кнопок.
Следующий фрагмент кода выполняется для каждого входящего уведомления: -
Так регистрируются действия с уведомлениями и тип уведомления
struct NotificationStruct {
struct Action {
static let positive = "positive"
static let negative = "negative"
}
}
//Registering notification actions with notificationCatagory
//This function called each time for incoming notification
func registerCatagory ()
{
let actionPositive = UNNotificationAction (
identifier : NotificationStruct.Action.positive,
title : buttonPositiveLabel,
options : []
)
let actionNegative = UNNotificationAction (
identifier : NotificationStruct.Action.negative,
title : buttonNegativeLabel,
options : []
)
let notificationCategory = UNNotificationCategory (
identifier : notificationId,
actions : [actionPositive, actionNegative],
intentIdentifiers : [],
options : []
)
UNUserNotificationCenter.current ()
.setNotificationCategories ([notificationCategory])
}
Вот так я регистрирую уведомление catagoryIdentifier для запуска уведомления:
func triggerNotificaion ()
{
let content = UNMutableNotificationContent ()
content.title = title
content.body = body
content.categoryIdentifier = notificationId
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 2, repeats: false)
let request = UNNotificationRequest (
identifier : String (getRandomId()),
content : content,
trigger : trigger
)
//scheduling the notification
UNUserNotificationCenter.current ()
.add (request, withCompletionHandler: nil)
}
func getRandomId () -> Int {
let randomInt = Int.random (in: 0..<999999)
return randomInt
}
Пожалуйста, ребята, помогите мне !!!