.

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Hi, dein ViewController muss NSUserNotificationCenterDelegate sein, also z.B.

    Quellcode

    1. extension ViewController: NSUserNotificationCenterDelegate {
    2. func userNotificationCenter(_ center: NSUserNotificationCenter, shouldPresent notification: NSUserNotification) -> Bool {
    3. return true
    4. }
    5. }

    hier musst func userNotificationCenter(_ center: NSUserNotificationCenter, shouldPresent notification: NSUserNotification) -> Bool {

    überschreiben und true zurückliefern.

    Dann weist du dem NSUserNotificationCenter den ViewController als Delegate zu.

    Quellcode

    1. ...
    2. let userNotificationCenter = NSUserNotificationCenter.default
    3. userNotificationCenter.delegate = self;
    4. ...
    5. userNotificationCenter.deliver(notification)