CFNotificationCenterAddObserver(_:_:_:_:_:_:)
Registers an observer to receive notifications.
Declaration
func CFNotificationCenterAddObserver(_ center: CFNotificationCenter!, _ observer: UnsafeRawPointer!, _ callBack: CFNotificationCallback!, _ name: CFString!, _ object: UnsafeRawPointer!, _ suspensionBehavior: CFNotificationSuspensionBehavior)Parameters
- center:
The notification center to which to add the observer.
- observer:
The observer. In macOS 10.3 and later, this parameter may be
NULL. - callBack:
The callback function to call when
objectposts the notification namedname. - name:
The name of the notification to observe. If
NULL,callbackis called for any notification posted byobject.If
centeris a Darwin notification center, this value must not beNULL. - object:
The object to observe. For distributed notifications,
objectmust be a CFString object. IfNULL,callbackis called when a notification namednameis posted by any object.If
centeris a Darwin notification center, this value is ignored. - suspensionBehavior:
Flag indicating how notifications should be handled when the application is in the background. See Cfnotificationsuspensionbehavior for the list of available values.
If
centeris a Darwin notification center, this value is ignored.
Discussion
Notification delivery is registered for the main thread.
If you need to control which thread processes a notification, your callback function must be able to forward the notification to the proper thread. You can use a CFMessagePort object or a custom CFRunLoopSource object to send notifications to the correct thread’s run loop.