Share via


AVAudioSession.Notifications.ObserveInterruption Metodo

Definizione

Overload

ObserveInterruption(EventHandler<AVAudioSessionInterruptionEventArgs>)

Notifica fortemente tipizzata per la InterruptionNotification costante.

ObserveInterruption(NSObject, EventHandler<AVAudioSessionInterruptionEventArgs>)

Notifica fortemente tipizzata per la InterruptionNotification costante.

ObserveInterruption(EventHandler<AVAudioSessionInterruptionEventArgs>)

Notifica fortemente tipizzata per la InterruptionNotification costante.

public static Foundation.NSObject ObserveInterruption (EventHandler<AVFoundation.AVAudioSessionInterruptionEventArgs> handler);
static member ObserveInterruption : EventHandler<AVFoundation.AVAudioSessionInterruptionEventArgs> -> Foundation.NSObject

Parametri

handler
EventHandler<AVAudioSessionInterruptionEventArgs>

Metodo da richiamare quando viene inviata la notifica.

Restituisce

Oggetto token che può essere usato per interrompere la ricezione delle notifiche eliminandolo o passandolo a RemoveObservers(IEnumerable<NSObject>)

Commenti

L'esempio seguente illustra come gli sviluppatori possono usare questo metodo nel codice:

//
// Lambda style
//

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

    Console.WriteLine ("InterruptionType", args.InterruptionType);
    Console.WriteLine ("Option", args.Option);
    Console.WriteLine ("WasSuspended", args.WasSuspended);
});

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

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

    Console.WriteLine ("InterruptionType", args.InterruptionType);
    Console.WriteLine ("Option", args.Option);
    Console.WriteLine ("WasSuspended", args.WasSuspended);
}

void Setup ()
{
    notification = AVAudioSession.Notifications.ObserveInterruption (Callback);
}

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

Si applica a

ObserveInterruption(NSObject, EventHandler<AVAudioSessionInterruptionEventArgs>)

Notifica fortemente tipizzata per la InterruptionNotification costante.

public static Foundation.NSObject ObserveInterruption (Foundation.NSObject objectToObserve, EventHandler<AVFoundation.AVAudioSessionInterruptionEventArgs> handler);
static member ObserveInterruption : Foundation.NSObject * EventHandler<AVFoundation.AVAudioSessionInterruptionEventArgs> -> Foundation.NSObject

Parametri

objectToObserve
NSObject

Oggetto specifico da osservare.

handler
EventHandler<AVAudioSessionInterruptionEventArgs>

Gestore che risponde alla notifica quando si verifica.

Restituisce

Oggetto token che può essere usato per interrompere la ricezione delle notifiche eliminandolo o passandolo a RemoveObservers(IEnumerable<NSObject>)

Commenti

Questo metodo può essere usato per sottoscrivere InterruptionNotification le notifiche.

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

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

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

Si applica a