Created
January 23, 2022 23:22
-
-
Save stuartcarnie/649b777a8f122af9954e021049c84da4 to your computer and use it in GitHub Desktop.
Watch all notifications posted to Notification Center
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Place this early in your application's startup process, such as an init | |
let cb: CFNotificationCallback = { (centre: CFNotificationCenter?, observer: UnsafeMutableRawPointer?, name: CFNotificationName?, object: UnsafeRawPointer?, userInfo: CFDictionary?) in | |
print("Notification: ", terminator: "") | |
if let name = name { | |
print("(\(name.rawValue)) ") | |
} else { | |
print() | |
} | |
if let obj = observer { | |
let obj2: AnyObject = Unmanaged.fromOpaque(obj).takeUnretainedValue() | |
if let obj3 = obj2 as? NSObject { | |
print(" observer: \(obj3.debugDescription)") | |
} | |
} | |
if let obj = object { | |
let obj2: AnyObject = Unmanaged.fromOpaque(obj).takeUnretainedValue() | |
if let obj3 = obj2 as? NSObject { | |
print(" object: \(obj3.debugDescription)") | |
} | |
} | |
if let userInfo = userInfo { | |
print("\(userInfo)") | |
} | |
} | |
CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(), nil, cb, nil, nil, .deliverImmediately) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment