-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMacapi.Notifications.pas
43 lines (33 loc) · 1.93 KB
/
Macapi.Notifications.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
unit Macapi.Notifications;
interface
uses
System.SysUtils, Macapi.Foundation, Macapi.Helpers;
/// <summary>Schedules a native Cocoa notification</summary>
procedure ScheduleNotification(const ATitle, ASubtitile, AInformation: String; const ADeliveryDate: TDateTime; const UseTimeZone: boolean = True);
/// <summary>Sends a native Cocoa notification</summary>
procedure PresentNotification(const ATitle, ASubtitile, AInformation: String);
implementation
procedure ScheduleNotification(const ATitle, ASubtitile, AInformation: String; const ADeliveryDate: TDateTime; const UseTimeZone: boolean = True);
begin
var ANotification: NSUserNotification := TNSUserNotification.Wrap(TNSUserNotification.Alloc.init);
if ATitle <> '' then
ANotification.setTitle(StrToNSStr(ATitle));
ANotification.setSubtitle(StrToNSStr(ASubtitile));
ANotification.setInformativeText(StrToNSStr(AInformation));
ANotification.setSoundName(NSUserNotificationDefaultSoundName);
ANotification.setDeliveryDate(DateTimeToNSDate(ADeliveryDate, UseTimeZone));
var ANotificationCenter: NSUserNotificationCenter := TNSUserNotificationCenter.Wrap(TNSUserNotificationCenter.OCClass.defaultUserNotificationCenter);
ANotificationCenter.scheduleNotification(ANotification);
end;
procedure PresentNotification(const ATitle, ASubtitile, AInformation: String);
begin
var ANotification: NSUserNotification := TNSUserNotification.Wrap(TNSUserNotification.Alloc.init);
if ATitle <> '' then
ANotification.setTitle(StrToNSStr(ATitle));
ANotification.setSubtitle(StrToNSStr(ASubtitile));
ANotification.setInformativeText(StrToNSStr(AInformation));
ANotification.setSoundName(NSUserNotificationDefaultSoundName);
var ANotificationCenter: NSUserNotificationCenter := TNSUserNotificationCenter.Wrap(TNSUserNotificationCenter.OCClass.defaultUserNotificationCenter);
ANotificationCenter.deliverNotification(ANotification);
end;
end.