Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS MacBase Plugin, MBS Mac64bit Plugin, MBS MacCloud Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Mac64bit/EventKit/EventKit
This example is the version from Fri, 3rd Mar 2022.
Project "EventKit.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
Note "Plugins"
for this example you need the following plugins:
MBS Mac64bit Plugin
MBS Main Plugin
MBS MacCloud Plugin
MBS MacBase Plugin
MBS MacCocoa Plugin
MBS MacControls Plugin
MBS MacCG Plugin
MBS MacCF Plugin
End Class
Class MainWindow Inherits Window
Control RequestAccessButton Inherits PushButton
ControlInstance RequestAccessButton Inherits PushButton
EventHandler Sub Action()
me.Enabled = False
EventStore.requestAccessToEntityType EventStore.kEntityTypeEvent
EventStore.requestAccessToEntityType EventStore.kEntityTypeReminder
End EventHandler
End Control
Control EventsButton Inherits PushButton
ControlInstance EventsButton Inherits PushButton
EventHandler Sub Action()
updateEvents
End EventHandler
End Control
Control NewEventButton Inherits PushButton
ControlInstance NewEventButton Inherits PushButton
EventHandler Sub Action()
dim r as new EKEventMBS(EventStore)
r.calendar = EventStore.defaultCalendarForNewEvents
r.title = "Testing EventKit"
r.location = "At my Mac"
r.startDate = new date
dim ed as new date
ed.Hour = ed.Hour + 1
r.endDate = ed
r.notes = "just a test"
dim e as NSErrorMBS
if EventStore.saveEvent(r, eventstore.kSpanThisEvent, true, e) then
MsgBox "OK"
else
MsgBox "Failed: "+e.LocalizedDescription
end if
Exception n as NSExceptionMBS
MsgBox n.message
End EventHandler
End Control
Control NewReminderButton Inherits PushButton
ControlInstance NewReminderButton Inherits PushButton
EventHandler Sub Action()
if EventStore.authorizationStatusForEntityType(EventStore.kEntityTypeReminder) = eventstore.kAuthorizationStatusNotDetermined then
// ask?
EventStore.requestAccessToEntityType EventStore.kEntityTypeReminder
return
end if
dim r as new EKReminderMBS(EventStore)
r.calendar = EventStore.defaultCalendarForNewReminders
r.priority = r.kPriorityMedium
r.title = "Test"
r.location = "At home"
dim c as new NSDateComponentsMBS
dim d as new date
c.hour = d.Hour+1
c.minute = d.Minute
c.second = d.Second
c.year = d.Year
c.month = d.month
c.day = d.day
'c.calendar = NSCalendarMBS.currentCalendar
c.Print
r.dueDateComponents = c
dim e as NSErrorMBS
if EventStore.saveReminder(r, true, e) then
MsgBox "OK"
else
MsgBox "Failed: "+e.LocalizedDescription
end if
Exception n as NSExceptionMBS
MsgBox n.message
End EventHandler
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Function CellClick(row as Integer, column as Integer, x as Integer, y as Integer) As Boolean
MsgBox me.Cell(row, column)
End EventHandler
End Control
Control RemindersButton Inherits PushButton
ControlInstance RemindersButton Inherits PushButton
EventHandler Sub Action()
updateReminders
End EventHandler
End Control
EventHandler Sub Open()
#if TargetMacOS and Target64Bit then
EventStore = new MyEventStore
#else
MsgBox "This example is for Xojo 2015r3 with 64-bit app."
#endif
End EventHandler
Sub GotPermissions(entityType as Integer, granted as Boolean)
if entityType = EventStore.kEntityTypeEvent then
NewEventButton.Enabled = granted
EventsButton.Enabled = granted
end if
if entityType = EventStore.kEntityTypeReminder then
NewReminderButton.Enabled = granted
RemindersButton.Enabled = granted
end if
RequestAccessButton.Enabled = not granted
End Sub
Sub updateEvents()
List.DeleteAllRows
dim startdate as new date
startdate.Day = 1
startdate.Hour = 0
startdate.Minute = 0
startdate.Second = 0
dim EndDate as new date(startdate)
EndDate.Month = EndDate.Month + 1
EndDate.Second = EndDate.Second -1 // move to last day
'MsgBox startdate.SQLDateTime+" "+EndDate.SQLDateTime
dim p as NSPredicateMBS = EventStore.predicateForEvents(startDate, endDate)
dim events() as EKEventMBS = EventStore.eventsMatchingPredicate(p)
for each e as EKEventMBS in events
List.addrow e.calendar.title, e.title, e.location, e.startDate.SQLDateTime, e.endDate.SQLDateTime
next
End Sub
Sub updateReminders()
dim startdate as new date
startdate.Day = 1
startdate.Hour = 0
startdate.Minute = 0
startdate.Second = 0
dim EndDate as new date(startdate)
EndDate.Month = EndDate.Month + 1
EndDate.Second = EndDate.Second -1 // move to last day
dim Predicate as NSPredicateMBS = EventStore.predicateForIncompleteRemindersWithDueDate(startdate, EndDate)
FetchRequest = EventStore.fetchRemindersMatchingPredicate(Predicate)
End Sub
Property EventStore As MyEventStore
Property FetchRequest As Variant
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class MyEventStore Inherits EKEventStoreMBS
EventHandler Sub Changed()
MainWindow.updateEvents
End EventHandler
EventHandler Sub fetchRemindersMatchingPredicateCompleted(reminders() as EKReminderMBS, predicate as NSPredicateMBS, tag as variant)
dim List as listbox = MainWindow.List
List.DeleteAllRows
for each r as EKReminderMBS in reminders
dim startDateComponents as NSDateComponentsMBS = r.startDateComponents
dim dueDateComponents as NSDateComponentsMBS = r.dueDateComponents
dim startDateComponentsDescription as string = DateComponentsString(startDateComponents)
dim dueDateComponentsDescription as string = DateComponentsString(dueDateComponents)
List.addrow r.calendar.title, r.title, r.location, startDateComponentsDescription, dueDateComponentsDescription
list.CellHelpTag(List.LastIndex, 3) = startDateComponentsDescription
list.CellHelpTag(List.LastIndex, 4) = dueDateComponentsDescription
next
End EventHandler
EventHandler Sub requestAccessToEntityTypeCompleted(entityType as Integer, granted as Boolean, error as NSErrorMBS, tag as variant)
System.DebugLog CurrentMethodName
if error <> nil then
System.DebugLog error.LocalizedDescription
end if
MainWindow.GotPermissions entityType, granted
End EventHandler
Function DateComponentsString(d as NSDateComponentsMBS) As String
dim s as string = d.description
dim lines() as string = split(s, EndOfLine)
lines.Remove 0
dim u as integer = lines.Ubound
for i as integer = 0 to u
lines(i) = lines(i).Trim
next
Return Join(lines, " ")
End Function
End Class
ExternalFile info
End ExternalFile
End Project
The items on this page are in the following plugins: MBS Mac64bit Plugin.