Search code examples
iosswiftnsnotificationcenternotificationcenter

Can I get all existing Notification Center messages using Swift?


I'm wondering is there a way to get all of the messages in Notification Center.

I already know how to post a message, but I don't know whether I can get the messages posted by other Apps into my App for usage.


Solution

  • Yes, you can:

    CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), nil, { (_, observer, name, _, _) in
            print("Notification \(name) received")
            }, nil, nil, .deliverImmediately)
    

    But be careful, there are a lot of notifications. :-)

    Please consider also this SO question.