gpt4 book ai didi

swift - 在 MacOS 中禁用重复通知

转载 作者:搜寻专家 更新时间:2023-11-01 05:33:26 25 4
gpt4 key购买 nike

我在这里给自己制造了一个很大的问题..

我想看看在 Xcode 中运行的应用程序的通知是否会继续以一分钟的间隔显示,即使在应用程序终止后也是如此。答案是肯定的。不幸的是,我在 viewDidLoad() 函数中运行了这段代码,所以应用程序在通知的一分钟间隔内加倍。我现在有超过一百万条通知,但我不知道如何在应用程序中禁用它们。我目前已关闭系统偏好设置中的通知,以防止由此导致的大量 CPU 使用率。

我的问题:什么是 MacOS 等同于 (iOS Swift 3) UIApplication.sharedApplication().cancelAllLocalNotifications()

我试过以下方法都没有用:

NSUserNotificationCenter.default.removeScheduledNotification(notification)

谢谢

编辑:添加了原始代码

            var notification = NSUserNotification()
notification.title = "Charge Level"
notification.informativeText = "\(self.BatteryLevel.intValue)%"
notification.hasActionButton = true
notification.deliveryTimeZone = NSTimeZone.local
var date = Date()
date.minute = 1
notification.deliveryDate = date
NSUserNotificationCenter.default.scheduleNotification(notification)

更新:Apple 支持似乎不理解这个问题,在他们的帮助下我一无所获,尽管我在系统偏好设置中关闭了它们,但我现在收到了数十亿条通知。这里真的需要帮助!!

最佳答案

为了解决这个问题,我发现删除通知中心缓存是有效的。以下是在终端中运行的内容。

cd $TMPDIR
cd ..
cd 0
sudo rm -rf ./com.apple.notificationcenter
killall NotificationCenter; killall usernoted

关于swift - 在 MacOS 中禁用重复通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48529371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com