首页 文章

iOS 10如何使用UNUserNotificationCenter查看待处理通知列表?

提问于
浏览
8

解决方案代码

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参数,我想不出它可能是什么 .

谢谢

1 回答

  • 25

    getPendingNotificationRequests 调用将一组请求传递给完成闭包 . 尝试这样的事情:

    let center = UNUserNotificationCenter.current()
    center.getPendingNotificationRequests(completionHandler: { requests in
        for request in requests {
            print(request)
        }
    })
    

相关问题