如何访问UNNotificationContent的标题?


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")
}

打印:

[& lt; UNNotificationRequest: 0 x600003c502a0;标识符:62F8BB2B-FC5D-40AE-8C43-6AFEEFBD9F0B,内容:, realert: 0, interruptionLevel: 1, relevanceScore: 0.00, trigger:{日历年:2022年7月:天:1111小时:分钟:49,重复:NO>祝辞]

标题和副标题显示为<'redacted'>。如何访问它们以向用户显示待处理的本地通知?

我找到了一个解决方案:

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("---------------------------------------------")
}
}

相关内容

  • 没有找到相关文章

最新更新