Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

NotificationCenterMBS class

Type Topic Plugin Version macOS Windows Linux Console & Web iOS
class Notifications MBS MacCF Plugin Yes No No Yes, macOS only No
Function: A class for notifications sent on Mac OS X.
From Apple's help, but modified:

Distributed notifications allow an application to broadcast a message to any number of other applications without needing to know who those other applications are, or even if the other applications exist. Every application type — Cocoa, Carbon, BSD — can use distributed notifications.

An application, the target application in this case, expresses an interest in receiving a broadcasted message by registering itself with the system's distributed notification center, identifying exactly what message, or notification type, it wants to receive. The notification type is defined by an arbitrary string agreed upon by the sender and receiver of the notification. As an example, Cocoa's NSWindow class defines the notification type "NSWindowDidCloseNotification", which an NSWindow instance broadcasts when its window closes. Any other object can register to receive this notification. (This notification, however, is internal to a single application and is not distributed to the rest of the system.)

In addition to the message, the application can identify the particular object sending the message. When the sender and receiver are in the same application—in other words, using nondistributed notifications—the observed object can be anything. When using distributed notifications, though, the object must be a string. A useful choice for the observed string is the bundle identifier of the target application.

In registering for the notification, the application provides a class with an Receive event, which will later be called.

Next, the broadcasting application — your preference pane — sends the notification. It calls the system's notification center, tells the center what notification to send, and optionally passes a dictionary containing additional information. The dictionary can be used to pass the modified preferences directly to the application. Or, the preference pane can choose not to use the dictionary and instead write the changes out to disk. The notification is then used to tell the application to update its preferences from the disk.

The notification center looks up all the applications that registered to receive the given notification type from the particular instance. It then notifies each application's run loop of the notification and gives it a copy of the dictionary. The selected callback function or method is executed during the application's next pass through its run loop.

When using Preference Services, be certain to flush changes to the disk with the appropriate synchronize functions before sending notifications of changes. Otherwise, due to the caching performed by Preference Services, the disk may not accurately reflect the changes when the target receives the notification. Likewise, the target application must resynchronize its preferences after receiving the notification.

Feedback, Comments & Corrections

This class has no sub classes.

Some examples which use this class:

Blog Entries

The items on this page are in the following plugins: MBS MacCF Plugin.

NikonSizeMBS   -   NotificationMBS

The biggest plugin in space...

MBS Xojo Plugins