Reputation:
func CalendarTriggeredNotification(givenDate: Date, roomName: String, itemName: String) {
let content = UNMutableNotificationContent()
content.title = "Freshness Check."
content.subtitle = "Room: \(roomName). Check on \(itemName)"
content.sound = UNNotificationSound.default
let dateComponent = Calendar.current.dateComponents([.day, .month, .year, .hour, .minute], from: givenDate)
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponent, repeats: false)
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request)
UNUserNotificationCenter.current().getPendingNotificationRequests { requests in
print(requests)
}
successNotificationBanner(title: "Reminder Saved")
}
Prints:
[<UNNotificationRequest: 0x600003c502a0; identifier: 62F8BB2B-FC5D-40AE-8C43-6AFEEFBD9F0B, content: <UNNotificationContent: 0x600000ee6a00; title: , subtitle: , body: (null), summaryArgument: , summaryArgumentCount: 0, categoryIdentifier: , launchImageName: , threadIdentifier: , attachments: ( ), badge: (null), sound: <UNNotificationSound: 0x6000019df170>, realert: 0, interruptionLevel: 1, relevanceScore: 0.00, trigger: <UNCalendarNotificationTrigger: 0x6000033efe40; dateComponents: <NSDateComponents: 0x6000030e8330> { Calendar Year: 2022 Month: 7 Day: 11 Hour: 11 Minute: 49, repeats: NO>>]
The title and subtitle read <'redacted'>
. How can I access them to show pending local notifications to users?
Upvotes: 0
Views: 445
Reputation:
I found a solution:
UNUserNotificationCenter.current().getPendingNotificationRequests { requests in
for request in requests {
print("---------------------------------------------")
print(request.identifier)
print(request.content.title)
print(request.content.body)
print(request.content.subtitle)
print("---------------------------------------------")
}
}
Upvotes: 0