FMX.Notification.Mac (Delphi)
Contents
Description
This example shows you how to use the TNotificationCenter component to implement notifications for your OS X applications using the OS X Notification Center.
To build and test this example:
- Create a Multi-Device application: File > New > Multi-Device Application - Delphi > Blank Application.
 - Add the following components to your form:
- Five TButton controls. In the Object Inspector, set the following properties:
 - A TNotificationCenter control. This component allows you to easily access the Notification Service.
 
 
- At this point, your form should look like this:
 
Code
Add the following code to the OnClick event handler for the ScheduleNotification.
procedure TDemonstration.ScheduleNotificationClick(Sender: TObject);
var
  MyNotification: TNotification;
begin
   // Create an instance of TNotification
  MyNotification := NotificationCenter1.CreateNotification;
  try
    MyNotification.Name := 'MyNotification';
    MyNotification.AlertBody := 'RAD Studio Rio is here!';
    // Fired in 5 seconds
    MyNotification.FireDate := Now + EncodeTime(0, 0, 5, 0);
    // Note: You must send the notification to '''Notification Center''' to be displayed.
    NotificationCenter1.ScheduleNotification(MyNotification);
  finally
    MyNotification.DisposeOf;
  end;
end;
Add the following code to the OnClick event handler for the Notification.
procedure TDemonstration.NotificationClick(Sender: TObject);
var
  MyNotification: TNotification;
begin
   // Create an instance of TNotification
  MyNotification := NotificationCenter1.CreateNotification;
  try
    MyNotification.Name := 'MyNotification';
    MyNotification.AlertBody := 'RAD Studio Rio is here now!';
    // Note: You must send the notification to '''Notification Center''' to be displayed.
    NotificationCenter1.PresentNotification(MyNotification);
  finally
    MyNotification.DisposeOf;
  end;
end;
Add the following code to the OnClick event handler for the RepeatNotification.
procedure TDemonstration.RepeatNotificationClick(Sender: TObject);
var
  MyNotification: TNotification;
begin
   // Create an instance of TNotification
  MyNotification := NotificationCenter1.CreateNotification;
  try
    MyNotification.Name := 'MyNotification';
    MyNotification.AlertBody := 'RAD Studio Rio is here!';
    // Fired in 5 seconds
    MyNotification.FireDate := Now + EncodeTime(0, 0, 5, 0);
	//Repeated each minute
    MyNotification.RepeatInterval := TRepeatInterval.Minute;
    // Note: You must send the notification to '''Notification Center''' to be displayed.
    NotificationCenter1.ScheduleNotification(MyNotification);
  finally
    MyNotification.DisposeOf;
  end;
end;
Add the following code to the OnClick event handler for the CancelScheduled.
procedure TDemonstration.CancelScheduledClick(Sender: TObject);
begin
  NotificationCenter1.CancelNotification('MyNotification');
  ShowMessage('Schedule Notifications cancelled');
end;
Add the following code to the OnClick event handler for the CancelAll.
procedure TDemonstration.CancelAllClick(Sender: TObject);
begin
  Notificationcenter1.CancelAll;
  ShowMessage('All Notifications canceled');
end;
You will get notification banners, unless you change the appropriate setting in System Settings > Notifications to get alerts.
Banner:
Alert:
Notification Center:
Uses
- FMX.Notification.TNotification
 - FMX.Notification.TNotificationCenter
 - FMX.Notification.TCustomNotificationCenter.CreateNotification
 - FMX.Notification.TCustomNotificationCenter.PresentNotification
 - FMX.Notification.TCustomNotificationCenter.ScheduleNotification
 - System.Notification.TNotification.RepeatInterval
 - FMX.Notification.TCustomNotificationCenter.CancelNotification
 - FMX.Notification.TCustomNotificationCenter.CancelAll
 



