SlideShare a Scribd company logo
1 of 18
Event Kit 
Framework 
Calendar. Reminder.
● Calendar.app 
● Reminders.app 
Event Kit Architecture
Requesting Permission to Access Calendars 
Init EKEventStore: 
eventStore = EKEventStore() 
Check authorization status: 
let status:EKAuthorizationStatus = EKEventStore.authorizationStatusForEntityType(EKEntityTypeEvent) 
switch (status) { 
case .Authorized: accessGrantedForCalendar() 
break 
case .NotDetermined: requestCalendarAccess() 
break 
case .Denied, .Restricted: 
break 
} 
Request Calendar access: 
eventStore?.requestAccessToEntityType(EKEntityTypeEvent, completion: { 
[weak self] (granted:Bool, error:NSError!) -> Void in 
dispatch_async(dispatch_get_main_queue()) { 
self!.accessGrantedForCalendar() 
} 
})
func fetchCallendarGroups(eventStore:EKEventStore) { 
for source in eventStore.sources() as [EKSource] { 
println("Group: title = (source.title)" + 
" type = (source.sourceType.value)") 
} 
} 
/* Log 
Group: title = Default type = 0 
Group: title = Other type = 5 
Group: title = Gmail type = 2 
Group: title = CalDAV type = 2 
Group: title = iCloud type = 2 
*/ 
Event. Fetch Calendar Groups
func fetchAllCallendars() { 
Event. Fetch All Calendars 
let calendars = eventStore.calendarsForEntityType(EKEntityTypeEvent) as [EKCalendar] 
for calendar in calendars { 
println("Calendar: title = (calendar.title)" + 
" type = (calendar.type.value)" + 
" allows modifications = (calendar.allowsContentModifications)") 
} 
} 
/* Log 
Calendar: title = Work type = 1 allows modifications = true 
Calendar: title = Home type = 1 allows modifications = true 
Calendar: title = Birthdays type = 4 allows modifications = false 
Calendar: title = a.voityuk@gmail.com type = 1 allows modifications = true 
Calendar: title = Calendar type = 1 allows modifications = false 
*/
Event. Fetch Events Using Predicates 
func fetchEvents(calendar: EKCalendar) { 
/* The event starts from today, right now */ 
let startDate = NSDate() 
/* The end date will be 7 day from now */ 
let endDate = startDate.dateByAddingTimeInterval(24 * 60 * 60 * 7) 
/* Create the predicate that we can later pass to the event store in order to fetch the events */ 
let searchPredicate = eventStore.predicateForEventsWithStartDate(startDate, endDate: endDate, calendars: nil) 
/* Fetch all the events that fall between the starting and the ending dates */ 
let events = eventStore.eventsMatchingPredicate(searchPredicate) as [EKEvent] 
for event in events { 
println("Event: title = (event.title)") 
} 
} 
/* Log 
Event: title = Alexander Voityuk’s 28. Birthday 
Event: title = Maxim Matyash’s 30. Birthday 
*/
func createEventWithTitle(title: String, startDate: NSDate, endDate: NSDate, inCalendar: EKCalendar, inEventStore: EKEventStore) -> Bool { 
/* Create an event */ 
var event = EKEvent(eventStore: inEventStore) 
event.calendar = inCalendar 
/* Set the properties of the event such as its title, start date/time, end date/time, etc. */ 
event.title = title 
event.startDate = startDate 
event.endDate = endDate 
/* Finally, save the event into the calendar */ 
var error:NSError? 
let result = inEventStore.saveEvent(event, 
span: EKSpanThisEvent, 
error: &error) 
return result 
} 
Event. Create Event
func removeEvent(event: EKEvent, store: EKEventStore, calendar: EKCalendar) -> Bool{ 
var result = false 
var error:NSError? 
/* remove the event from the calendar */ 
if store.removeEvent(event, 
span: EKSpanThisEvent, 
commit: true, 
error: &error) { 
result = true 
} else if let theError = error { 
println("Failed to remove (event) with error = (theError)") 
} 
return result 
} 
Event. Remove Event
func addAlarmToCalendarWithStore(title: String, startDate: NSDate, endDate: NSDate, store: EKEventStore, calendar: EKCalendar) { 
/* Assign the required properties, especially the target calendar */ 
let eventWithAlarm = EKEvent(eventStore: store) 
eventWithAlarm.title = title 
eventWithAlarm.calendar = calendar 
eventWithAlarm.startDate = startDate 
eventWithAlarm.endDate = endDate 
/* The alarm goes off 2 seconds before the event happens */ 
let alarm = EKAlarm(relativeOffset: -2.0) 
eventWithAlarm.addAlarm(alarm) 
var error:NSError? 
if store.saveEvent(eventWithAlarm, span: EKSpanThisEvent, error: &error) { 
println("Saved an event that fires 60 seconds from now.") 
} else if let theError = error { 
println("Failed to save the event. Error = (theError)") 
} 
} 
Event. Add Alarm
func addRecurringRuleToEvent(event: EKEvent) { 
/* The end date of the recurring rule is one year from now */ 
let oneYear:NSTimeInterval = 365 * 24 * 60 * 60; 
let oneYearFromNow = startDate.dateByAddingTimeInterval(oneYear) 
/* Create an Event Kit date from this date */ 
let recurringEnd = EKRecurrenceEnd.recurrenceEndWithEndDate(oneYearFromNow) as EKRecurrenceEnd 
/* And the recurring rule. This event happens every 
month (EKRecurrenceFrequencyMonthly), once a month (interval:1) 
and the recurring rule ends a year from now (end:RecurringEnd) */ 
let recurringRule = EKRecurrenceRule( 
recurrenceWithFrequency: EKRecurrenceFrequencyMonthly, 
interval: 1, 
end: recurringEnd) 
/* Set the recurring rule for the event */ 
event.recurrenceRules = [recurringRule] 
} 
Event. Add Recurring Rule
func fetchAllCallendars() { 
Reminder. Fetch All Calendars 
let calendars = eventStore.calendarsForEntityType(EKEntityTypeReminder) as [EKCalendar] 
for calendar in calendars { 
println("Calendar: title = (calendar.title)" + 
" type = (calendar.type.value)" + 
" allows modifications = (calendar.allowsContentModifications)") 
} 
} 
/* Log 
Calendar: title = Reminders type = 1 allows modifications = true 
*/
Reminder. Fetch Reminders Using Predicates 
func fetchReminders(calendar: EKCalendar) -> NSMutableArray { 
/* The event starts from today, right now */ 
let startDate = NSDate() 
/* The end date will 7day from now */ 
let endDate = startDate.dateByAddingTimeInterval(24 * 60 * 60 * 7) 
/* Create the predicate that we can later pass to the event store in order to fetch the events */ 
let searchPredicate = eventStore.predicateForIncompleteRemindersWithDueDateStarting(startDate, ending: endDate, calendars: nil) 
/* Fetch all the reminder that fall between the starting and the ending dates */ 
eventStore.fetchRemindersMatchingPredicate(searchPredicate, completion: { 
(reminders) -> Void in 
for reminder in reminders { 
println("Event: title = (reminder.title)") 
} 
}) 
} 
/* Log 
Reminder: title = My Reminder 1 
Reminder: title = My Reminder 2 
*/
func createReminderWithTitle(title: String, inCalendar: EKCalendar, inEventStore: EKEventStore, notes: String) -> Bool { 
/* Create an reminder */ 
var reminder = EKReminder(eventStore: inEventStore) 
reminder.calendar = inCalendar 
/* Set the properties of the event such as its title, notes. */ 
reminder.title = title 
reminder.notes = notes 
/* Finally, save the reminder into the calendar */ 
var error:NSError? 
let result = inEventStore.saveReminder(reminder, 
commit: true, 
error: &error) 
if result == false { 
if let theError = error{ 
println("An error occurred (theError)") 
} 
} 
return result 
} 
Reminder. Create Reminder
func removeReminder(reminder: EKReminder, store: EKEventStore, calendar: EKCalendar) -> Bool{ 
var result = false 
var error:NSError? 
/* remove the reminder from the calendar */ 
if store.removeReminder(reminder, 
commit: true, 
error: &error) { 
result = true 
} else if let theError = error{ 
println("Failed to remove (reminder) with error = (theError)") 
} 
return result 
} 
Reminder. Remove Reminder
/* Add observer */ 
NSNotificationCenter.defaultCenter().addObserver( 
self, 
selector: "eventStoreDidChanged:", 
name: EKEventStoreChangedNotification, 
object: nil) 
func eventStoreDidChanged(notification:NSNotification) { 
// TODO 
} 
Observing External Changes 
to the Calendar Database
Add delegate EKEventViewDelegate to current ViewController 
func displayExistingEvent(event : EKEvent, store : EKEventStore) { 
let controller:EKEventViewController = EKEventViewController() 
controller.event = event; 
controller.allowsEditing = true; 
self.presentViewController(UINavigationController(rootViewController: controller), animated: true, completion: nil) 
} 
// MARK: - EKEventViewDelegate 
func eventViewController(controller: EKEventViewController!, didCompleteWithAction action: EKEventViewAction) { 
self.dismissViewControllerAnimated(true, completion: { 
() -> Void in 
// TODO 
}) 
} 
Interfaces for Events. Displaying Event Data
Add delegate EKEventEditViewDelegate to current ViewController 
func editExistingEvent(event : EKEvent, store : EKEventStore) { 
let controller:EKEventEditViewController = EKEventEditViewController() 
controller.event = event 
controller.eventStore = store 
controller.editViewDelegate = self 
self.presentViewController(controller, animated: true, completion: nil) 
} 
// MARK: - EKEventEditViewDelegate 
func eventEditViewController(controller: EKEventEditViewController!, didCompleteWithAction action: EKEventEditViewAction) { 
self.dismissViewControllerAnimated(true, completion: { 
() -> Void in 
// TODO 
}) 
} 
func eventEditViewControllerDefaultCalendarForNewEvents(controller: EKEventEditViewController!) -> EKCalendar! { 
return defaultCalendar 
} 
Interfaces for Events. Modifying Event Data
End 
Calendar and Reminders Programming Guide: 
https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/EventKitProgGuide/Introduction/Introduction.html 
Apple Sample Project “SimpleEKDemo”: 
https://developer.apple.com/library/ios/samplecode/SimpleEKDemo/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010160

More Related Content

What's hot

Drools 6.0 (CamelOne 2013)
Drools 6.0 (CamelOne 2013)Drools 6.0 (CamelOne 2013)
Drools 6.0 (CamelOne 2013)Mark Proctor
 
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos AiresJavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos AiresRobert Nyman
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileJavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileRobert Nyman
 
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresJavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresRobert Nyman
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, MontevideoJavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, MontevideoRobert Nyman
 
Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Robert DeLuca
 
Data20161007
Data20161007Data20161007
Data20161007capegmail
 
Nodejs do teste de unidade ao de integração
Nodejs  do teste de unidade ao de integraçãoNodejs  do teste de unidade ao de integração
Nodejs do teste de unidade ao de integraçãoVinícius Pretto da Silva
 
KODE JS POKENNNNN
KODE JS POKENNNNNKODE JS POKENNNNN
KODE JS POKENNNNNPipo Atem
 
Get the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for XamarinGet the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for XamarinXamarin
 
Effective Android Data Binding
Effective Android Data BindingEffective Android Data Binding
Effective Android Data BindingEric Maxwell
 
Awesome State Management for React and Other Virtual-Dom Libraries
Awesome State Management for React and Other Virtual-Dom LibrariesAwesome State Management for React and Other Virtual-Dom Libraries
Awesome State Management for React and Other Virtual-Dom LibrariesFITC
 
Xamarin: Introduction to iOS 8
Xamarin: Introduction to iOS 8Xamarin: Introduction to iOS 8
Xamarin: Introduction to iOS 8Xamarin
 
Modern Android Architecture
Modern Android ArchitectureModern Android Architecture
Modern Android ArchitectureEric Maxwell
 
Cnam azure 2014 mobile services
Cnam azure 2014   mobile servicesCnam azure 2014   mobile services
Cnam azure 2014 mobile servicesAymeric Weinbach
 
Technology and Science News - ABC News
Technology and Science News - ABC NewsTechnology and Science News - ABC News
Technology and Science News - ABC Newsenchantingsched84
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of ControlChad Hietala
 

What's hot (20)

Drools 6.0 (CamelOne 2013)
Drools 6.0 (CamelOne 2013)Drools 6.0 (CamelOne 2013)
Drools 6.0 (CamelOne 2013)
 
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos AiresJavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, ChileJavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
 
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos AiresJavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, MontevideoJavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Montevideo
 
Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React
 
Data20161007
Data20161007Data20161007
Data20161007
 
Road to react hooks
Road to react hooksRoad to react hooks
Road to react hooks
 
Nodejs do teste de unidade ao de integração
Nodejs  do teste de unidade ao de integraçãoNodejs  do teste de unidade ao de integração
Nodejs do teste de unidade ao de integração
 
KODE JS POKENNNNN
KODE JS POKENNNNNKODE JS POKENNNNN
KODE JS POKENNNNN
 
Get the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for XamarinGet the Most Out of iOS 11 with Visual Studio Tools for Xamarin
Get the Most Out of iOS 11 with Visual Studio Tools for Xamarin
 
Javascript - Beyond-jQuery
Javascript - Beyond-jQueryJavascript - Beyond-jQuery
Javascript - Beyond-jQuery
 
Effective Android Data Binding
Effective Android Data BindingEffective Android Data Binding
Effective Android Data Binding
 
Awesome State Management for React and Other Virtual-Dom Libraries
Awesome State Management for React and Other Virtual-Dom LibrariesAwesome State Management for React and Other Virtual-Dom Libraries
Awesome State Management for React and Other Virtual-Dom Libraries
 
Xamarin: Introduction to iOS 8
Xamarin: Introduction to iOS 8Xamarin: Introduction to iOS 8
Xamarin: Introduction to iOS 8
 
Modern Android Architecture
Modern Android ArchitectureModern Android Architecture
Modern Android Architecture
 
Cnam azure 2014 mobile services
Cnam azure 2014   mobile servicesCnam azure 2014   mobile services
Cnam azure 2014 mobile services
 
I os 04
I os 04I os 04
I os 04
 
Technology and Science News - ABC News
Technology and Science News - ABC NewsTechnology and Science News - ABC News
Technology and Science News - ABC News
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Control
 

Similar to iOS. EventKit Framework. Work with calendars and reminders

Architecting JavaScript Code
Architecting JavaScript CodeArchitecting JavaScript Code
Architecting JavaScript CodeSuresh Balla
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScriptkvangork
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascriptkvangork
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesAnkit Rastogi
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Librariesjeresig
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao PauloJavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao PauloRobert Nyman
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it meansRobert Nyman
 
Formacion en movilidad: Conceptos de desarrollo en iOS (IV)
Formacion en movilidad: Conceptos de desarrollo en iOS (IV) Formacion en movilidad: Conceptos de desarrollo en iOS (IV)
Formacion en movilidad: Conceptos de desarrollo en iOS (IV) Mobivery
 
Redux for ReactJS Programmers
Redux for ReactJS ProgrammersRedux for ReactJS Programmers
Redux for ReactJS ProgrammersDavid Rodenas
 
Google App Engine Developer - Day3
Google App Engine Developer - Day3Google App Engine Developer - Day3
Google App Engine Developer - Day3Simon Su
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbroncymbron
 
DWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A TutorialDWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A Tutorialjbarciauskas
 
Data in Motion: Streaming Static Data Efficiently
Data in Motion: Streaming Static Data EfficientlyData in Motion: Streaming Static Data Efficiently
Data in Motion: Streaming Static Data EfficientlyMartin Zapletal
 
Expert JavaScript tricks of the masters
Expert JavaScript  tricks of the mastersExpert JavaScript  tricks of the masters
Expert JavaScript tricks of the mastersAra Pehlivanian
 
State management in android applications
State management in android applicationsState management in android applications
State management in android applicationsGabor Varadi
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Paco de la Cruz
 
Advanced Akka For Architects
Advanced Akka For ArchitectsAdvanced Akka For Architects
Advanced Akka For ArchitectsLightbend
 
HTML5 & The Open Web - at Nackademin
HTML5 & The Open Web -  at NackademinHTML5 & The Open Web -  at Nackademin
HTML5 & The Open Web - at NackademinRobert Nyman
 

Similar to iOS. EventKit Framework. Work with calendars and reminders (20)

Architecting JavaScript Code
Architecting JavaScript CodeArchitecting JavaScript Code
Architecting JavaScript Code
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScript
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascript
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao PauloJavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
JavaScript APIs - The Web is the Platform - MDN Hack Day, Sao Paulo
 
JavaScript Refactoring
JavaScript RefactoringJavaScript Refactoring
JavaScript Refactoring
 
The Open Web and what it means
The Open Web and what it meansThe Open Web and what it means
The Open Web and what it means
 
Formacion en movilidad: Conceptos de desarrollo en iOS (IV)
Formacion en movilidad: Conceptos de desarrollo en iOS (IV) Formacion en movilidad: Conceptos de desarrollo en iOS (IV)
Formacion en movilidad: Conceptos de desarrollo en iOS (IV)
 
Redux for ReactJS Programmers
Redux for ReactJS ProgrammersRedux for ReactJS Programmers
Redux for ReactJS Programmers
 
Google App Engine Developer - Day3
Google App Engine Developer - Day3Google App Engine Developer - Day3
Google App Engine Developer - Day3
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbron
 
DWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A TutorialDWR, Hibernate and Dojo.E - A Tutorial
DWR, Hibernate and Dojo.E - A Tutorial
 
Data in Motion: Streaming Static Data Efficiently
Data in Motion: Streaming Static Data EfficientlyData in Motion: Streaming Static Data Efficiently
Data in Motion: Streaming Static Data Efficiently
 
Expert JavaScript tricks of the masters
Expert JavaScript  tricks of the mastersExpert JavaScript  tricks of the masters
Expert JavaScript tricks of the masters
 
State management in android applications
State management in android applicationsState management in android applications
State management in android applications
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)
 
Advanced Akka For Architects
Advanced Akka For ArchitectsAdvanced Akka For Architects
Advanced Akka For Architects
 
HTML5 & The Open Web - at Nackademin
HTML5 & The Open Web -  at NackademinHTML5 & The Open Web -  at Nackademin
HTML5 & The Open Web - at Nackademin
 
Grails on GAE/J
Grails on GAE/JGrails on GAE/J
Grails on GAE/J
 

Recently uploaded

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Recently uploaded (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

iOS. EventKit Framework. Work with calendars and reminders

  • 1. Event Kit Framework Calendar. Reminder.
  • 2. ● Calendar.app ● Reminders.app Event Kit Architecture
  • 3. Requesting Permission to Access Calendars Init EKEventStore: eventStore = EKEventStore() Check authorization status: let status:EKAuthorizationStatus = EKEventStore.authorizationStatusForEntityType(EKEntityTypeEvent) switch (status) { case .Authorized: accessGrantedForCalendar() break case .NotDetermined: requestCalendarAccess() break case .Denied, .Restricted: break } Request Calendar access: eventStore?.requestAccessToEntityType(EKEntityTypeEvent, completion: { [weak self] (granted:Bool, error:NSError!) -> Void in dispatch_async(dispatch_get_main_queue()) { self!.accessGrantedForCalendar() } })
  • 4. func fetchCallendarGroups(eventStore:EKEventStore) { for source in eventStore.sources() as [EKSource] { println("Group: title = (source.title)" + " type = (source.sourceType.value)") } } /* Log Group: title = Default type = 0 Group: title = Other type = 5 Group: title = Gmail type = 2 Group: title = CalDAV type = 2 Group: title = iCloud type = 2 */ Event. Fetch Calendar Groups
  • 5. func fetchAllCallendars() { Event. Fetch All Calendars let calendars = eventStore.calendarsForEntityType(EKEntityTypeEvent) as [EKCalendar] for calendar in calendars { println("Calendar: title = (calendar.title)" + " type = (calendar.type.value)" + " allows modifications = (calendar.allowsContentModifications)") } } /* Log Calendar: title = Work type = 1 allows modifications = true Calendar: title = Home type = 1 allows modifications = true Calendar: title = Birthdays type = 4 allows modifications = false Calendar: title = a.voityuk@gmail.com type = 1 allows modifications = true Calendar: title = Calendar type = 1 allows modifications = false */
  • 6. Event. Fetch Events Using Predicates func fetchEvents(calendar: EKCalendar) { /* The event starts from today, right now */ let startDate = NSDate() /* The end date will be 7 day from now */ let endDate = startDate.dateByAddingTimeInterval(24 * 60 * 60 * 7) /* Create the predicate that we can later pass to the event store in order to fetch the events */ let searchPredicate = eventStore.predicateForEventsWithStartDate(startDate, endDate: endDate, calendars: nil) /* Fetch all the events that fall between the starting and the ending dates */ let events = eventStore.eventsMatchingPredicate(searchPredicate) as [EKEvent] for event in events { println("Event: title = (event.title)") } } /* Log Event: title = Alexander Voityuk’s 28. Birthday Event: title = Maxim Matyash’s 30. Birthday */
  • 7. func createEventWithTitle(title: String, startDate: NSDate, endDate: NSDate, inCalendar: EKCalendar, inEventStore: EKEventStore) -> Bool { /* Create an event */ var event = EKEvent(eventStore: inEventStore) event.calendar = inCalendar /* Set the properties of the event such as its title, start date/time, end date/time, etc. */ event.title = title event.startDate = startDate event.endDate = endDate /* Finally, save the event into the calendar */ var error:NSError? let result = inEventStore.saveEvent(event, span: EKSpanThisEvent, error: &error) return result } Event. Create Event
  • 8. func removeEvent(event: EKEvent, store: EKEventStore, calendar: EKCalendar) -> Bool{ var result = false var error:NSError? /* remove the event from the calendar */ if store.removeEvent(event, span: EKSpanThisEvent, commit: true, error: &error) { result = true } else if let theError = error { println("Failed to remove (event) with error = (theError)") } return result } Event. Remove Event
  • 9. func addAlarmToCalendarWithStore(title: String, startDate: NSDate, endDate: NSDate, store: EKEventStore, calendar: EKCalendar) { /* Assign the required properties, especially the target calendar */ let eventWithAlarm = EKEvent(eventStore: store) eventWithAlarm.title = title eventWithAlarm.calendar = calendar eventWithAlarm.startDate = startDate eventWithAlarm.endDate = endDate /* The alarm goes off 2 seconds before the event happens */ let alarm = EKAlarm(relativeOffset: -2.0) eventWithAlarm.addAlarm(alarm) var error:NSError? if store.saveEvent(eventWithAlarm, span: EKSpanThisEvent, error: &error) { println("Saved an event that fires 60 seconds from now.") } else if let theError = error { println("Failed to save the event. Error = (theError)") } } Event. Add Alarm
  • 10. func addRecurringRuleToEvent(event: EKEvent) { /* The end date of the recurring rule is one year from now */ let oneYear:NSTimeInterval = 365 * 24 * 60 * 60; let oneYearFromNow = startDate.dateByAddingTimeInterval(oneYear) /* Create an Event Kit date from this date */ let recurringEnd = EKRecurrenceEnd.recurrenceEndWithEndDate(oneYearFromNow) as EKRecurrenceEnd /* And the recurring rule. This event happens every month (EKRecurrenceFrequencyMonthly), once a month (interval:1) and the recurring rule ends a year from now (end:RecurringEnd) */ let recurringRule = EKRecurrenceRule( recurrenceWithFrequency: EKRecurrenceFrequencyMonthly, interval: 1, end: recurringEnd) /* Set the recurring rule for the event */ event.recurrenceRules = [recurringRule] } Event. Add Recurring Rule
  • 11. func fetchAllCallendars() { Reminder. Fetch All Calendars let calendars = eventStore.calendarsForEntityType(EKEntityTypeReminder) as [EKCalendar] for calendar in calendars { println("Calendar: title = (calendar.title)" + " type = (calendar.type.value)" + " allows modifications = (calendar.allowsContentModifications)") } } /* Log Calendar: title = Reminders type = 1 allows modifications = true */
  • 12. Reminder. Fetch Reminders Using Predicates func fetchReminders(calendar: EKCalendar) -> NSMutableArray { /* The event starts from today, right now */ let startDate = NSDate() /* The end date will 7day from now */ let endDate = startDate.dateByAddingTimeInterval(24 * 60 * 60 * 7) /* Create the predicate that we can later pass to the event store in order to fetch the events */ let searchPredicate = eventStore.predicateForIncompleteRemindersWithDueDateStarting(startDate, ending: endDate, calendars: nil) /* Fetch all the reminder that fall between the starting and the ending dates */ eventStore.fetchRemindersMatchingPredicate(searchPredicate, completion: { (reminders) -> Void in for reminder in reminders { println("Event: title = (reminder.title)") } }) } /* Log Reminder: title = My Reminder 1 Reminder: title = My Reminder 2 */
  • 13. func createReminderWithTitle(title: String, inCalendar: EKCalendar, inEventStore: EKEventStore, notes: String) -> Bool { /* Create an reminder */ var reminder = EKReminder(eventStore: inEventStore) reminder.calendar = inCalendar /* Set the properties of the event such as its title, notes. */ reminder.title = title reminder.notes = notes /* Finally, save the reminder into the calendar */ var error:NSError? let result = inEventStore.saveReminder(reminder, commit: true, error: &error) if result == false { if let theError = error{ println("An error occurred (theError)") } } return result } Reminder. Create Reminder
  • 14. func removeReminder(reminder: EKReminder, store: EKEventStore, calendar: EKCalendar) -> Bool{ var result = false var error:NSError? /* remove the reminder from the calendar */ if store.removeReminder(reminder, commit: true, error: &error) { result = true } else if let theError = error{ println("Failed to remove (reminder) with error = (theError)") } return result } Reminder. Remove Reminder
  • 15. /* Add observer */ NSNotificationCenter.defaultCenter().addObserver( self, selector: "eventStoreDidChanged:", name: EKEventStoreChangedNotification, object: nil) func eventStoreDidChanged(notification:NSNotification) { // TODO } Observing External Changes to the Calendar Database
  • 16. Add delegate EKEventViewDelegate to current ViewController func displayExistingEvent(event : EKEvent, store : EKEventStore) { let controller:EKEventViewController = EKEventViewController() controller.event = event; controller.allowsEditing = true; self.presentViewController(UINavigationController(rootViewController: controller), animated: true, completion: nil) } // MARK: - EKEventViewDelegate func eventViewController(controller: EKEventViewController!, didCompleteWithAction action: EKEventViewAction) { self.dismissViewControllerAnimated(true, completion: { () -> Void in // TODO }) } Interfaces for Events. Displaying Event Data
  • 17. Add delegate EKEventEditViewDelegate to current ViewController func editExistingEvent(event : EKEvent, store : EKEventStore) { let controller:EKEventEditViewController = EKEventEditViewController() controller.event = event controller.eventStore = store controller.editViewDelegate = self self.presentViewController(controller, animated: true, completion: nil) } // MARK: - EKEventEditViewDelegate func eventEditViewController(controller: EKEventEditViewController!, didCompleteWithAction action: EKEventEditViewAction) { self.dismissViewControllerAnimated(true, completion: { () -> Void in // TODO }) } func eventEditViewControllerDefaultCalendarForNewEvents(controller: EKEventEditViewController!) -> EKCalendar! { return defaultCalendar } Interfaces for Events. Modifying Event Data
  • 18. End Calendar and Reminders Programming Guide: https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/EventKitProgGuide/Introduction/Introduction.html Apple Sample Project “SimpleEKDemo”: https://developer.apple.com/library/ios/samplecode/SimpleEKDemo/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010160