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

aes*_*abs 9 ios swift3 ios10 unusernotificationcenter

解决方案代码

let center = UNUserNotificationCenter.current()
print(center.getPendingNotificationRequests(completionHandler: { error in
        // error handling here
    }))
Run Code Online (Sandbox Code Playgroud)

我的原帖:

我正在尝试通过UNUserNotificationCenter获取待处理通知的列表UIApplication.shared.scheduledLocalNotifications.

这是我正在使用的代码:

let center = UNUserNotificationCenter.current()
    print(UNUserNotificationCenter.getPendingNotificationRequests(center))
Run Code Online (Sandbox Code Playgroud)

但是这会打印"(功能)".getPendingNotificationRequests需要一个UNUserNotificationCenter参数,我想不出它可能是什么.

谢谢

Jer*_*rry 28

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

let center = UNUserNotificationCenter.current()
center.getPendingNotificationRequests(completionHandler: { requests in
    for request in requests {
        print(request)
    }
})
Run Code Online (Sandbox Code Playgroud)

  • 在 ios 13 中它总是给我 0..我使用的是设备而不是模拟器..对此有什么想法吗? (5认同)
  • 通知正在正确安排。但获取请求数为0。 (2认同)
  • @Abhishek 我也有同样的问题。你已经想通了吗? (2认同)