Skip to content

Notification Center

levching edited this page Apr 15, 2020 · 3 revisions

The NotificationCenter provides a notification dispatch mechanism that enables the broadcast of information to registered observers. Most likely you will be using ISN_NSNotificationCenter object to subscribe to some Media, Social or System events.

Default Center

All system notifications sent to an app are posted to the defaultCenter notification center. You can also post your own notifications there.

If your app uses notifications extensively, you may want to create and post to your own notification centers rather than posting only to the defaultCenter notification center. When a notification is posted to a notification center, the notification center scans through the list of registered observers, which may slow down your app. By organizing notifications functionally around one or more notification centers, less work is done each time a notification is posted, which can improve performance throughout your app.

The code snippet below shows how to get an instance of the default notification center:

using SA.iOS.Foundation;
...
var center = ISN_NSNotificationCenter.DefaultCenter;

Add Observer

Adds an entry to the notification center's dispatch table that includes a notification queue and a block to add to the queue, and an optional notification name and sender.

The name of the notification for which to register the observer; that is, only notifications with this name are used to add the block to the operation queue.

For example, here how can I subscribe to the media player playback notifications:

using SA.iOS.Foundation;
using SA.iOS.MediaPlayer;
...

var center = ISN_NSNotificationCenter.DefaultCenter;
center.AddObserverForName(ISN_MPMusicPlayerController.NowPlayingItemDidChange, 
    (ISN_NSNotification notification) => {
        UpdatePlayerStateUI();
        Debug.Log("MusicPlayer Now Playing Item Did Change");
});

About

Foundation

AV Foundation

App Tracking Transparency

Game Kit

Store Kit

UI Kit

Social

Replay Kit

Contacts

AVKit

Photos

App Delegate

User Notifications

MediaPlayer

Core Location

AdSupport

EventKit

CloudKit

Authentication Services

XCode

Knowledge Base

Clone this wiki locally