MonoMac 0.0.0.0 MonoMac.Foundation.NSObject MonoMac.Foundation.Register("NSNotificationCenter", true) A notification hub for the application.

The NSNotificationCenter is a hub that is used to listen to broadcast messages and post broadcast messages in an application. The messages that are posted are synchronous.

The NSNotificationCenter.DefaultCenter plays a central role in the application as this is where system notifications are posted for interesting system-level events.

Posting a notification is a synchronous process, which means that invoking one of the Post messages on the notification center will block execution until all of the notification handlers have completed running.

Notifications are posted on the same thread as the calling thread which could have undesired effects. If you need to deliver notifications from a background thread, use the method to wrap your posting into a delegate that is invoked on the main thread.

When subscribing to a notification, it is possible to subscribe only to a certain kind of notification by specifying the notification name (or null to listen to all notifications posted to the notification center). It is also possible to subscribe only to notifications issued by a specific object. This can be used to filter the amount of notifications received.

Notifications are usually NSString fields that are hosted in some class, for example the Objetive-C UITextViewTextDidChangeNotification is found in the class UITextView as the . For convenience there are overloads that take C# strings.

To register for notifications, you can use the AddObserver method. We recommend that you use the C# versions of these methods, as you can directly connect delegates, lambdas and methods directly into your code. When you use any of the AddObserver methods in this class that take an Action<NSNotification;> parameter, the AddObserver will return a token. This token is then used as the parameter to RemoveNotification when you want to stop listening to a particular event.

`NSObject notificationToken; void Setup () { notificationToken = NSNotificationCenter.DefaultCenter.AddObserver (FooBar.ClockNotification, OnClockChange); } void OnClockChange (NSNotification notification) { Console.WriteLine ("The ClockNotification message was posted"); } void Teardown () { NSNotificationCenter.DefaultCenter.RemoveObserver (notificationToken); }`

Starting with MonoMac 5.4, calling Dispose on the returned notification token will also remove the observer for you, making the code shorter. For example:

`NSObject notificationToken; void Setup () { notificationToken = NSNotificationCenter.DefaultCenter.AddObserver (FooBar.ClockNotification, OnClockChange); } void OnClockChange (NSNotification notification) { Console.WriteLine ("The ClockNotification message was posted"); } void Teardown () { notificationToken.Dispose (); }` AppPrefs monocatalog
- Constructor
  0.0.0.0
  MonoMac.Foundation.Export("init")
  System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)
  Default constructor that initializes a new instance of this class with no parameters.
- Constructor
  0.0.0.0
  MonoMac.Foundation.Export("initWithCoder:")
  System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)
  The unarchiver object.
  A constructor that initializes the object from the data stored in the unarchiver object.
  This constructor is provided to allow the class to be initialized from an unarchiver (for example, during NIB deserialization).
- Constructor
  0.0.0.0
  System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)
  Unused sentinel value, pass NSObjectFlag.Empty.
  Constructor to call on derived classes when the derived class has an [Export] constructor.

  This constructor should be called by derived classes when they are initialized using an [Export] attribute. The argument value is ignore, typically the chaining would look like this:

  public class MyClass : BaseClass { [Export ("initWithFoo:")] public MyClass (string foo) : base (NSObjectFlag.Empty) { ... }
- Constructor
  0.0.0.0
  System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)
  Pointer (handle) to the unmanaged object.
  A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

  This constructor is invoked by the runtime infrastructure () to create a new managed representation for a pointer to an unmanaged Objective-C object. You should not invoke this method directly, instead you should call the GetNSObject method as it will prevent two instances of a managed object to point to the same native object.

- Method
  0.0.0.0
  MonoMac.Foundation.NSObject `` `` The name of the notification to observe. The delegate that will be invoked when the notification is posted. Adds an observer for the specified notification An observer token that can be used later as the parameter passed to RemoveObserver (NSObject observer).
- Method
  0.0.0.0
  System.Obsolete("Use AddObserver(NSString, Action<NSNotification>) instead")
  MonoMac.Foundation.NSObject `` `` The name of the notification to observe. The delegate that will be invoked when the notification is posted. Adds an observer for the specified notification An observer token that can be used later as the parameter passed to RemoveObserver (NSObject observer). Use this overload if you are using a C# string. Usually you would be using an NSString constant using the pattern ClassName.SomeNotification.
- Method
  0.0.0.0
  MonoMac.Foundation.NSObject `` `` `` The name of the notification to observe. The delegate that will be invoked when the notification is posted. If not-null, filters the notifications to those sent by this object. Adds an observer for the specified notification An observer token that can be used later as the parameter passed to RemoveObserver (NSObject observer).
- Method
  0.0.0.0
  System.Obsolete("Use AddObserver(NSString, Action<NSNotification>, NSObject)")
  MonoMac.Foundation.NSObject `` `` `` The name of the notification to observe. The delegate that will be invoked when the notification is posted. If not-null, filters the notifications to those sent by this object. Adds an observer for the specified notification An observer token that can be used later as the parameter passed to RemoveObserver (NSObject observer). Use this overload if you are using a C# string. Usually you would be using an NSString constant using the pattern ClassName.SomeNotification.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("addObserver:selector:name:object:")
  System.Void `` `` `` `` To be added. To be added.

  Optional name that you want to register with and filter delivery by this name. Use null if you do not want filtering to take place.

  This parameter can be .

  The object that we want to receive notifications from, or null for receiving the specified notifications sent by all objects.

  This parameter can be .

  Low-level add-bserver API

  This is a low-level version of the AddObserver API that allows the consumer to contorl the observer and the selector to notify upon notifications.

  Users are encouraged to use the high-level variant.

- Method
  0.0.0.0
  System.Obsolete("Use AddObserver(NSObject, Selector, NSString, NSObject) instead")
  System.Void `` `` `` `` To be added. To be added. To be added. To be added. To be added.

  This is a low-level version of the AddObserver API that allows the consumer to contorl the observer and the selector to notify upon notifications.

  Users are encouraged to use the high-level variant.

- Method
  0.0.0.0
  MonoMac.Foundation.Export("addObserverForName:object:queue:usingBlock:")
  System.Void `` `` `` `` To be added. To be added. To be added. To be added. To be added. To be added.
- Property
  0.0.0.0
  System.IntPtr The handle for this class. The pointer to the Objective-C class. Each MonoMac class mirrors an unmanaged Objective-C class. This value contains the pointer to the Objective-C class, it is similar to calling objc_getClass with the object name.
- Property
  0.0.0.0
  get: MonoMac.Foundation.Export("defaultCenter")
  MonoMac.Foundation.NSNotificationCenter The default notification center, system notifications and system-level events are posted to this notification center.

  The NSNotificationCenter.DefaultCenter plays a central role in the application as this is where system notifications are posted for interesting system-level events.

- Method
  0.0.0.0
  MonoMac.Foundation.Export("postNotification:")
  System.Void `` Notification to post Posts a notification that is broadcast to everyoned subscribing to that notification.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("postNotificationName:object:")
  System.Void `` `` To be added.

  The reference object posting this notification, can be null.

  This parameter can be .

  To be added. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("postNotificationName:object:userInfo:")
  System.Void `` `` `` To be added.

  The reference object posting this notification, can be null.

  This parameter can be .

  To be added.

  This parameter can be .

  To be added. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("removeObserver:")
  System.Void `` To be added. To be added. The observer parameter is either the return value from the AddObserver methods that take a Action<NSNotification> parameter (the C# style API) or the "observer" parameter that is passed to AddObserver (the Objective-C style API).
- Method
  0.0.0.0
  MonoMac.Foundation.Export("removeObserver:name:object:")
  System.Void `` `` `` To be added.

  Optional name that you registered. Use null if you do not want filtering to take place.

  This parameter can be .

  The object that you originally registered interest in.

  This parameter can be .

  To be added. To be added.
- Method
  0.0.0.0
  System.Void `` To be added. Removes multiple observers in one call. This removes all of the observers in the IEnumerable<NSObject> parameter.