For my app I have to create a Calendar in the user's iCloud account and add events to that calendar.
I am Creating calendar using this:
let newCalendar = EKCalendar(forEntityType: EKEntityTypeEvent, eventStore: EventManager.sharedInstance.eventStore)
newCalendar.title = "MyAppCalendar"
let color = UIColor(red: CGFloat(arc4random_uniform(255))/255, green: CGFloat(arc4random_uniform(255))/255, blue: CGFloat(arc4random_uniform(255))/255, alpha: 1)
newCalendar.CGColor = color.CGColor
var mySource:EKSource?
for source in EventManager.sharedInstance.eventStore?.sources() as! [EKSource] {
if source.sourceType.value == EKSourceTypeCalDAV.value && source.title == "iCloud" {
mySource = source
break
}
}
if mySource == nil {
//crearting alert and displaying to user
return
}
else {
newCalendar.source = mySource!
}
var error:NSError?
if EventManager.sharedInstance.eventStore!.saveCalendar(newCalendar, commit: true, error: &error) {
let calendarName = newCalendar.title
let calendarIdentifier = newCalendar.calendarIdentifier
//save these in db and server
}else {
SharedConstants.handleErrors(error!)
}
Where EventManager
is my class to maintain reference to EKEventStore
object instance.
But in Apple documentation it says that the calendarIdentifier changes on syncing.
So my question is how to maintain a reference to this calendar?