How can you create an iCloud Calender for an iOS app to use with swift? -
i've seen many people search user's calendars , grab first 1 that's writable , start throwing events on there. don't practice; prefer respect users little more.
so how can make own calendar app use events creates?
i came following function, assuming app allowed access users calendars:
let eventstore = ekeventstore() func checkcalendar() -> ekcalendar { var retcal: ekcalendar? let calendars = eventstore.calendarsforentitytype(ekentitytypeevent) as! [ekcalendar] // grab every calendar user has var exists: bool = false calendar in calendars { // search these calendars if calendar.title == "any string" { exists = true retcal = calendar } } var err : nserror? if !exists { let newcalendar = ekcalendar(forentitytype:ekentitytypeevent, eventstore:eventstore) newcalendar.title="any string" newcalendar.source = eventstore.defaultcalendarfornewevents.source eventstore.savecalendar(newcalendar, commit:true, error:&err) retcal = newcalendar } return retcal! }
this function looks calendar name of "any string". of course, can like. if doesn't exist, create it. returns calendar, can assign calendar variable , work please.
Comments
Post a Comment