【发布时间】:2017-07-18 20:03:03
【问题描述】:
我正在尝试编写一个函数来检查我是否已达到 64 个本地通知的限制。有一些解决 UIlocalNotifications 的答案,但我还没有找到 NSlocalNotifications 的答案。这是我的功能
func notificationLimitreached() {
let center = UNUserNotificationCenter.current()
var limit = false
center.getPendingNotificationRequests(completionHandler: { requests in
print(requests.count)
if requests.count > 59 {
limit = true
print(limit)
} else {
limit = false
}
})
print (limit)
问题是“limit”变量在闭包内打印 true,然后在离开闭包后重置为 false 的初始值。
我尝试过的其他方法。
-- 在我读取此值时再次在闭包内设置全局变量,否则将其设置为原始值
【问题讨论】:
标签: ios swift localnotification