`UNTimeIntervalNotificationTrigger` repeats: true only fired once. macOS bug? Works on iOS

霸气de小男生 提交于 2020-06-01 05:48:06

问题


I want a notification to show every 60 seconds. It only happened once on MacOS. The same exact code works normally on iOS.

If I manually remove the notification from macOS notification center, it'll eventually show again. So the problem seems like notification won't show again if it's already showed once and the user didn't take any action.

Did I miss something obvious here?

Current macOS: 10.15.4 Current iOS: 13.4.1

on App Delegate

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler([.alert, .badge, .sound])
    }

on DidLaunch equivalent (iOS and macOS)

let center = UNUserNotificationCenter.current()
        center.delegate = self

        center.requestAuthorization(options: [.alert, .sound, .badge]) { (grant, err) in
            if grant {
                let content = UNMutableNotificationContent()
                content.title = "AY"
                let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true)
                let req = UNNotificationRequest(identifier: "ay", content: content, trigger: trigger)
                center.add(req)
            }
        }

来源:https://stackoverflow.com/questions/61872174/untimeintervalnotificationtrigger-repeats-true-only-fired-once-macos-bug-wo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!