SyncKit allows you to synchronize system events and calendars with your database.
- Conform your Event and Calendar class to
SKEvent
andSKCalendar
class Event: SKEvent {
var title: String
var eventIdentifier: String
var lastModifiedDate: Date?
...
func toEKEvent() -> EKEvent {
if let event = store.event(withIdentifier: eventIdentifier) {
event.title = title
...
return event
} else {
let event = EKEvent(eventStore: store)
...
return event
}
}
}
- Request access to event( You must implement Privacy keys in your
info.plist
) - Compare events and calendars stored in your app with system ones.
let comparison = SKCenter.shared.compareCalendars(calendars: systemCalendars, storedCalendars: storedCalendars)
- Update your app
db.save(comparison.calendarsToSave)
db.update(comparison.calendarsToUpdate)
db.remove(comparison.calendarsToDelete)