There are no action buttons in local iOS notifications

I am just building my first application, and I was probably faced with the biggest problem in it. I tried to do repeated local notifications, for loops, each of which has a different category, but for some reason it does not work. I get all the notifications, but when I pull the notification to see the actions, I don't see any actions. Have you ever encountered such a problem, and if you do, how did you manage to solve it? trying to do, repeat the local notifications scheduled for today.

Here is my code:

for index in 0..<workingDays[3].subjects!.count {
    howManyLeft -= 1
    var seperated = workingDays[3].subjects![index].endsAt!.components(separatedBy: ":")
    var dateComponents = DateComponents()
    dateComponents.hour = Int(seperated[0])
    dateComponents.minute = Int(seperated[1])
    dateComponents.weekday = 5

    // make category
    let actionBaby = UNNotificationAction(identifier: "oneaction\(index)", title: "something\(index)", options: .foreground)
    let category = UNNotificationCategory(identifier: "\(index).5", actions: [actionBaby], intentIdentifiers: [], hiddenPreviewsBodyPlaceholder: "idk", options: [])
    UNUserNotificationCenter.current().setNotificationCategories([category])

    // If contition is true make notification
    if index + 1 >= 0 && index + 1 < workingDays[3].subjects!.count {
        let notification = UNMutableNotificationContent()
        notification.categoryIdentifier = "\(index).5"
        notification.title = "someRandom\(index)"
        let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
        let request = UNNotificationRequest(identifier: "\(index)5",
            content: notification,
            trigger: trigger)
        UNUserNotificationCenter.current().add(request)
    }
}
+4
source share

No one has answered this question yet.

See related questions:

87
1
1
0
,
-1
?

Source: https://habr.com/ru/post/1689404/


All Articles