Compartilhar via


UIApplication.WillEnterForegroundNotification Propriedade

Definição

Constante de notificação para WillEnterForeground

[Foundation.Advice("Use UIApplication.Notifications.ObserveWillEnterForeground helper method instead.")]
[Foundation.Field("UIApplicationWillEnterForegroundNotification", "UIKit")]
public static Foundation.NSString WillEnterForegroundNotification { get; }
member this.WillEnterForegroundNotification : 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 esta notificação, poderá usar a conveniência UIApplication.Notifications. Método M:UIKit.UIKit.UIApplication.Notifications.ObserveWillEnterForeground*, que 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 = UIApplication.Notifications.ObserveWillEnterForeground ((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 = UIApplication.Notifications.ObserveWillEnterForeground (Callback);
}

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

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

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


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

void Setup ()
{
    NSNotificationCenter.DefaultCenter.AddObserver (UIApplication.WillEnterForegroundNotification, Callback);
}

Aplica-se a