Upravit

Sdílet prostřednictvím


CFNotificationCenter.AddObserver Method

Definition

Adds an observer to the notification center.

public CoreFoundation.CFNotificationObserverToken AddObserver (string name, ObjCRuntime.INativeObject objectToObserve, Action<string,Foundation.NSDictionary> notificationHandler, CoreFoundation.CFNotificationSuspensionBehavior suspensionBehavior = CoreFoundation.CFNotificationSuspensionBehavior.DeliverImmediately);
member this.AddObserver : string * ObjCRuntime.INativeObject * Action<string, Foundation.NSDictionary> * CoreFoundation.CFNotificationSuspensionBehavior -> CoreFoundation.CFNotificationObserverToken

Parameters

name
String

Name of the notification to observer, or null if you want the notificationHandler to be invoked for all notifications posted. null is not allowed for the Darwin notification center.

objectToObserve
INativeObject

For non-Darwin notification centers, the object to observe. If null is passed, then the notificationHandler is invoked for all objects that have a notification named name posted.

notificationHandler
Action<String,NSDictionary>

Handler to invoke when a notification is posted.

suspensionBehavior
CFNotificationSuspensionBehavior

Determines how a notification is processed when the application is in the background.

Returns

Token representing the notification, use this token if you want to later remove this observer.

Remarks

Registers a method to be invoked when a notification is posted to a specific object.

The handler is invoked on the same thread that posted the message, or from the loop that pumped the notification. If your code needs to run in a specific thread, you should take care of that in your handler.

Use the returned value as a token to RemoveObserver(CFNotificationObserverToken) if you want to stop getting notifications.

Applies to