首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS 10如何使用UNUserNotificationCenter查看挂起通知的列表?

iOS 10如何使用UNUserNotificationCenter查看挂起通知的列表?
EN

Stack Overflow用户
提问于 2016-10-26 19:24:42
回答 4查看 15.9K关注 0票数 19

解决方案代码:

代码语言:javascript
复制
let center = UNUserNotificationCenter.current()
print(center.getPendingNotificationRequests(completionHandler: { error in
        // error handling here
    }))

我最初的帖子:

我正在尝试通过UNUserNotificationCenter获取挂起通知的列表,因为UIApplication.shared.scheduledLocalNotifications被折旧了。

这是我使用的代码:

代码语言:javascript
复制
let center = UNUserNotificationCenter.current()
    print(UNUserNotificationCenter.getPendingNotificationRequests(center))

然而,这个打印“(函数)”。getPendingNotificationRequests需要一个UNUserNotificationCenter参数,我想不出它还能是什么。

谢谢

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2016-10-29 04:57:00

getPendingNotificationRequests调用将一个请求数组传递给完成闭包。试着做这样的事情:

代码语言:javascript
复制
let center = UNUserNotificationCenter.current()
center.getPendingNotificationRequests(completionHandler: { requests in
    for request in requests {
        print(request)
    }
})
票数 43
EN

Stack Overflow用户

发布于 2020-10-06 19:10:24

如果有人需要访问已经传递的通知(用户可以在通知中心看到它们),可以通过以下方式完成:

代码语言:javascript
复制
    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
        }
    }
票数 4
EN

Stack Overflow用户

发布于 2020-03-03 18:20:36

实际上不是现在,但您应该允许使用通知

代码语言:javascript
复制
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
        if !granted {
            print("user has declined notifications")
        }
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40270598

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档