我只是在制作我的第一个应用程序,我可能面临其中最大的问题。我尝试使用 for 循环重复本地通知,每个通知都有不同的类别,但由于某种原因它不起作用。我实际上收到了所有通知,但是当我拉下通知以查看操作时,我没有看到任何操作。您是否遇到过这种问题,如果您遇到了,您是如何解决的?我的通知试图重复今天安排的本地通知。
这是我的代码:
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)
}
}