FMX.Notification.Mac (C++)
From Appmethod Code Examples
Contents
Description
This example shows you how to use the TNotificationCenter component to implement notifications for your Mac 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 - C++ > 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.
void __fastcall TDemonstration::ScheduleNotificationClick(TObject *Sender) { if (NotificationCenter1->Supported()) { TNotification *myNotification = NotificationCenter1->CreateNotification(); __try { myNotification->Name = "MyNotification"; myNotification->AlertBody = "Appmethod 1.16 is here!"; // Fire in 10 seconds myNotification->FireDate = Now() + EncodeTime(0, 0, 10, 0); // Send notification to the Notification Center NotificationCenter1->ScheduleNotification(myNotification); } __finally { myNotification->DisposeOf(); } } }
Add the following code to the OnClick event handler for the Notification.
void __fastcall TDemonstration::PresentNotificationClick(TObject *Sender) { if (NotificationCenter1->Supported()) { TNotification *myNotification = NotificationCenter1->CreateNotification(); __try { myNotification->Name = "MyNotification"; myNotification->AlertBody = "Appmethod 1.16 is here!"; // Send notification to the Notification Center NotificationCenter1->PresentNotification(myNotification); } __finally { myNotification->DisposeOf(); } } }
Add the following code to the OnClick event handler for the RepeatNotification.
void __fastcall TDemonstration::RepeatNotificationClick(TObject *Sender) { if (NotificationCenter1->Supported()) { TNotification *myNotification = NotificationCenter1->CreateNotification(); __try { myNotification->Name = "MyNotification"; myNotification->AlertBody = "Appmethod 1.16 is here!"; // Fire in 10 seconds myNotification->FireDate = Now() + EncodeTime(0, 0, 10, 0); // Repeated each minute myNotification->RepeatInterval = TRepeatInterval::Minute; // Send notification to the Notification Center NotificationCenter1->ScheduleNotification(myNotification); } __finally { myNotification->DisposeOf(); } } }
Add the following code to the OnClick event handler for the CancelScheduled.
void __fastcall TDemonstration::CancelScheduleClick(TObject *Sender) { NotificationCenter1->CancelNotification("MyNotification"); ShowMessage("Schedule Notifications cancelled"); }
Add the following code to the OnClick event handler for the CancelAll.
void __fastcall TDemonstration::CancelAllClick(TObject *Sender) { NotificationCenter1->CancelAll(); ShowMessage("All Notifications canceled"); }
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