Creating a new CalDav Reminder Calendar with MBS EventKit

Hello,

i am trying to create a new Reminder Calendar (CalDav) on OS X in a 64Bit App, using the EventKit Plugin from the MBS Complete Package.
Gaining access to the EventStore works fine and i can read and write Events/Reminders just fine, but when i try to create a new Reminder Calendar, nothing happens. No error message no hints in the OS X console.

I am using the following Code to create a new Calendar:

[code] Dim r As New EKCalendarMBS(1, App.EventStore)
dim e as NSErrorMBS
r.title = “Test”
dim rc() as EKCalendarMBS = App.EventStore.calendarsForEntityType(1)
rc.Append®
App.EventStore.Commit(e)

If e<>Nil Then MsgBox e.LocalizedDescription

Exception n as NSExceptionMBS
MsgBox n.message[/code]

Can you please help me to solve this issue?
Thank you for your kind help.

appending a calendar to an array does not add it to the database.

You should call saveCalendar method in EventStore.

Thank you Christian.

I tried this before with this Code:

[code] Dim r As New EKCalendarMBS(1, EventStore)
dim e as NSErrorMBS

r.title = “Test”

dim rc() as EKCalendarMBS = EventStore.calendarsForEntityType(1)

rc.Append®

If EventStore.saveCalendar(r, True, e) Then

MsgBox "OK"

Else

MsgBox e.LocalizedDescription

End If

Exception n as NSExceptionMBS
MsgBox n.message
[/code]

But i always get a “Calendar has no account” (German: “Kalender hat kein Account”) error.

Got it finally working… :slight_smile:

[code] Dim r As New EKCalendarMBS(1, EventStore)
dim e as NSErrorMBS

Dim s() As EKSourceMBS

r.title = “Test”

dim rc() as EKCalendarMBS = EventStore.calendarsForEntityType(1)

s = EventStore.sources()

For Each ss As EKSourceMBS In s

If ss.title = "iCloud" Then 
  
  r.source = ss
  
End If

Next

rc.Append®

If EventStore.saveCalendar(r, True, e) Then

MsgBox "OK"

Else

MsgBox e.LocalizedDescription

End If

Exception n as NSExceptionMBS
MsgBox n.message[/code]

The missing part was the Source (the Account) and the above code is just a Quick & Dirty result from Try & Error attempts. But it’s working. :slight_smile:

[code]Function CreateNewCalendar(CalendarName As String, CalendarEntityType As Integer, Optional CalendarAccount As String = “iCloud”) As String
Dim theCalendar As New EKCalendarMBS(CalendarEntityType, EventStore)
dim kitError as NSErrorMBS
Dim theSources() As EKSourceMBS
dim ReminderCalendars() as EKCalendarMBS = EventStore.calendarsForEntityType(CalendarEntityType)

theCalendar.title = CalendarName

theSources = EventStore.sources()

For Each tempSource As EKSourceMBS In theSources

If tempSource.title = CalendarAccount Then 
  
  theCalendar.source = tempSource
  
  ReminderCalendars.Append(theCalendar)
  
  If EventStore.saveCalendar(theCalendar, True, kitError)  Then
    
    Return "OK"
    
  Else
    
    Return kitError.LocalizedDescription
    
  End If
  
  Exit For tempSource
  
End If

Next

Exception n as NSExceptionMBS
Return n.message
End Function
[/code]