Share via


NSUserDefaults.Notifications.ObserveDidChange Método

Definición

Sobrecargas

ObserveDidChange(EventHandler<NSNotificationEventArgs>)

Notificación fuertemente tipada para la DidChangeNotification constante.

ObserveDidChange(NSObject, EventHandler<NSNotificationEventArgs>)

Notificación fuertemente tipada para la DidChangeNotification constante.

ObserveDidChange(EventHandler<NSNotificationEventArgs>)

Notificación fuertemente tipada para la DidChangeNotification constante.

public static Foundation.NSObject ObserveDidChange (EventHandler<Foundation.NSNotificationEventArgs> handler);
static member ObserveDidChange : EventHandler<Foundation.NSNotificationEventArgs> -> Foundation.NSObject

Parámetros

handler
EventHandler<NSNotificationEventArgs>

Método para invocar cuando se publica la notificación.

Devoluciones

Objeto de token que se puede usar para dejar de recibir notificaciones al eliminarlo o pasarlo a RemoveObservers(IEnumerable<NSObject>)

Comentarios

Este método se puede usar para suscribirse DidChangeNotification a las notificaciones.

// Listen to all notifications posted for any object
var token = NSUserDefaults.Notifications.ObserveDidChange ((notification) => {
	Console.WriteLine ("Observed DidChangeNotification!");
};

// Listen to all notifications posted for a single object
var token = NSUserDefaults.Notifications.ObserveDidChange (objectToObserve, (notification) => {
	Console.WriteLine ($"Observed DidChangeNotification for {nameof (objectToObserve)}!");
};

// Stop listening for notifications
token.Dispose ();

Se aplica a

ObserveDidChange(NSObject, EventHandler<NSNotificationEventArgs>)

Notificación fuertemente tipada para la DidChangeNotification constante.

public static Foundation.NSObject ObserveDidChange (Foundation.NSObject objectToObserve, EventHandler<Foundation.NSNotificationEventArgs> handler);
static member ObserveDidChange : Foundation.NSObject * EventHandler<Foundation.NSNotificationEventArgs> -> Foundation.NSObject

Parámetros

objectToObserve
NSObject

Objeto que se va a observar.

handler
EventHandler<NSNotificationEventArgs>

Método para invocar cuando se publica la notificación.

Devoluciones

Objeto de token que se puede usar para dejar de recibir notificaciones al eliminarlo o pasarlo a RemoveObservers(IEnumerable<NSObject>)

Comentarios

Este método se puede usar para suscribirse DidChangeNotification a las notificaciones.

// Listen to all notifications posted for any object
var token = NSUserDefaults.Notifications.ObserveDidChange ((notification) => {
	Console.WriteLine ("Observed DidChangeNotification!");
};

// Listen to all notifications posted for a single object
var token = NSUserDefaults.Notifications.ObserveDidChange (objectToObserve, (notification) => {
	Console.WriteLine ($"Observed DidChangeNotification for {nameof (objectToObserve)}!");
};

// Stop listening for notifications
token.Dispose ();

Se aplica a