Freigeben über


AVAudioSession.Notifications.ObserveInterruption Methode

Definition

Überlädt

ObserveInterruption(EventHandler<AVAudioSessionInterruptionEventArgs>)

Stark typisierte Benachrichtigung für die InterruptionNotification Konstante.

ObserveInterruption(NSObject, EventHandler<AVAudioSessionInterruptionEventArgs>)

Stark typisierte Benachrichtigung für die InterruptionNotification Konstante.

ObserveInterruption(EventHandler<AVAudioSessionInterruptionEventArgs>)

Stark typisierte Benachrichtigung für die InterruptionNotification Konstante.

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

Parameter

handler
EventHandler<AVAudioSessionInterruptionEventArgs>

Methode, die aufgerufen wird, wenn die Benachrichtigung bereitgestellt wird.

Gibt zurück

Tokenobjekt, das verwendet werden kann, um den Empfang von Benachrichtigungen zu beenden, indem es entweder entfernt oder an übergeben wird RemoveObservers(IEnumerable<NSObject>)

Hinweise

Das folgende Beispiel zeigt, wie Entwickler diese Methode in ihrem Code verwenden können:

//
// 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 ();
}

Gilt für:

ObserveInterruption(NSObject, EventHandler<AVAudioSessionInterruptionEventArgs>)

Stark typisierte Benachrichtigung für die InterruptionNotification Konstante.

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

Parameter

objectToObserve
NSObject

Das spezifische zu beobachtende Objekt.

handler
EventHandler<AVAudioSessionInterruptionEventArgs>

Der Handler, der auf die Benachrichtigung reagiert, wenn sie auftritt.

Gibt zurück

Tokenobjekt, das verwendet werden kann, um den Empfang von Benachrichtigungen zu beenden, indem es entweder entfernt oder an übergeben wird RemoveObservers(IEnumerable<NSObject>)

Hinweise

Diese Methode kann verwendet werden, um Benachrichtigungen zu abonnieren InterruptionNotification .

// 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 ();

Gilt für: