解决方案代码:
let center = UNUserNotificationCenter.current()
print(center.getPendingNotificationRequests(completionHandler: { error in
// error handling here
}))我最初的帖子:
我正在尝试通过UNUserNotificationCenter获取挂起通知的列表,因为UIApplication.shared.scheduledLocalNotifications被折旧了。
这是我使用的代码:
let center = UNUserNotificationCenter.current()
print(UNUserNotificationCenter.getPendingNotificationRequests(center))然而,这个打印“(函数)”。getPendingNotificationRequests需要一个UNUserNotificationCenter参数,我想不出它还能是什么。
谢谢
发布于 2016-10-29 04:57:00
getPendingNotificationRequests调用将一个请求数组传递给完成闭包。试着做这样的事情:
let center = UNUserNotificationCenter.current()
center.getPendingNotificationRequests(completionHandler: { requests in
for request in requests {
print(request)
}
})发布于 2020-10-06 19:10:24
如果有人需要访问已经传递的通知(用户可以在通知中心看到它们),可以通过以下方式完成:
let center = UNUserNotificationCenter.current()
center.getDeliveredNotifications { notifications in
// use center.removeDeliveredNotifications(withIdentifiers:requestIdsToRemove)
// if you want to cancel some of the notifications displayed to user
}
}发布于 2020-03-03 18:20:36
实际上不是现在,但您应该允许使用通知
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
if !granted {
print("user has declined notifications")
}
}https://stackoverflow.com/questions/40270598
复制相似问题