Compartilhar via


UIScreen.DidConnectNotification Propriedade

Definição

Constante de notificação para DidConnect

[Foundation.Advice("Use UIScreen.Notifications.ObserveDidConnect helper method instead.")]
[Foundation.Field("UIScreenDidConnectNotification", "UIKit")]
public static Foundation.NSString DidConnectNotification { get; }
member this.DidConnectNotification : Foundation.NSString

Valor da propriedade

Constante NSString, deve ser usada como um token para NSNotificationCenter.

Atributos

Comentários

Essa constante pode ser usada com o NSNotificationCenter para registrar um ouvinte para essa notificação. Esse é um NSString em vez de uma cadeia de caracteres, pois esses valores podem ser usados como tokens em algumas bibliotecas nativas em vez de serem usados puramente para seu conteúdo de cadeia de caracteres real. O parâmetro 'notification' para o retorno de chamada contém informações extras específicas para o tipo de notificação.

Se você quiser assinar essa notificação, poderá usar o método .ObserveDidConnect de conveniência UIScreen.Notificationsque oferece acesso fortemente tipado aos parâmetros da notificação.

O exemplo a seguir mostra como usar a classe Notifications fortemente tipada para tirar a adivinhação das propriedades disponíveis na notificação:

//
// Lambda style
//

// listening
notification = UIScreen.Notifications.ObserveDidConnect ((sender, args) => {
    /* Access strongly typed args */
    Console.WriteLine ("Notification: {0}", args.Notification);
});

// To stop listening:
notification.Dispose ();

//
// Method style
//
NSObject notification;
void Callback (object sender, Foundation.NSNotificationEventArgs args)
{
    // Access strongly typed args
    Console.WriteLine ("Notification: {0}", args.Notification);
}

void Setup ()
{
    notification = UIScreen.Notifications.ObserveDidConnect (Callback);
}

void Teardown ()
{
    notification.Dispose ();
}

O exemplo a seguir mostra como usar a notificação com a API DefaultCenter:

// Lambda style
NSNotificationCenter.DefaultCenter.AddObserver (
        UIScreen.DidConnectNotification, (notification) => {Console.WriteLine ("Received the notification UIScreen", notification); }


// Method style
void Callback (NSNotification notification)
{
    Console.WriteLine ("Received a notification UIScreen", notification);
}

void Setup ()
{
    NSNotificationCenter.DefaultCenter.AddObserver (UIScreen.DidConnectNotification, Callback);
}

Aplica-se a