SlideShare a Scribd company logo
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

Javascript pour les Développeurs WEB
Javascript pour les Développeurs WEBJavascript pour les Développeurs WEB
Javascript pour les Développeurs WEB
Abbes Rharrab
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & Vuex
Bernd Alter
 
Gestion comptes bancaires Spring boot
Gestion comptes bancaires Spring bootGestion comptes bancaires Spring boot
Gestion comptes bancaires Spring boot
Abdelhakim HADI ALAOUI
 
Workshop Spring - Session 4 - Spring Batch
Workshop Spring -  Session 4 - Spring BatchWorkshop Spring -  Session 4 - Spring Batch
Workshop Spring - Session 4 - Spring BatchAntoine Rey
 
Xen Hypervisor.pptx
Xen Hypervisor.pptxXen Hypervisor.pptx
Xen Hypervisor.pptx
RiyaBatool
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
军 沈
 
Cours javascript v1
Cours javascript v1Cours javascript v1
Cours javascript v1
TheBest Icanbe
 
JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿
Myungjin Lee
 
JHipster on AWS
JHipster on AWSJHipster on AWS
JHipster on AWS
Gerard Gigliotti
 
An Introduction to OpenCL™ Programming with AMD GPUs - AMD & Acceleware Webinar
An Introduction to OpenCL™ Programming with AMD GPUs - AMD & Acceleware WebinarAn Introduction to OpenCL™ Programming with AMD GPUs - AMD & Acceleware Webinar
An Introduction to OpenCL™ Programming with AMD GPUs - AMD & Acceleware Webinar
AMD Developer Central
 
Introduction to Reactive programming
Introduction to Reactive programmingIntroduction to Reactive programming
Introduction to Reactive programming
Dwi Randy Herdinanto
 
The virtual DOM and how react uses it internally
The virtual DOM and how react uses it internallyThe virtual DOM and how react uses it internally
The virtual DOM and how react uses it internally
Clóvis Neto
 
Spring Framework Petclinic sample application
Spring Framework Petclinic sample applicationSpring Framework Petclinic sample application
Spring Framework Petclinic sample application
Antoine Rey
 
Concevoir, développer et sécuriser des micro-services avec Spring Boot
Concevoir, développer et sécuriser des micro-services avec Spring BootConcevoir, développer et sécuriser des micro-services avec Spring Boot
Concevoir, développer et sécuriser des micro-services avec Spring Boot
DNG Consulting
 
Support JEE Spring Inversion de Controle IOC et Spring MVC
Support JEE Spring Inversion de Controle IOC et Spring MVCSupport JEE Spring Inversion de Controle IOC et Spring MVC
Support JEE Spring Inversion de Controle IOC et Spring MVC
ENSET, Université Hassan II Casablanca
 
WEB SERVICE SOAP, JAVA, XML, JAXWS
WEB SERVICE SOAP, JAVA, XML, JAXWSWEB SERVICE SOAP, JAVA, XML, JAXWS
WEB SERVICE SOAP, JAVA, XML, JAXWS
Lhouceine OUHAMZA
 
Vert.x for Microservices Architecture
Vert.x for Microservices ArchitectureVert.x for Microservices Architecture
Vert.x for Microservices Architecture
Idan Fridman
 
Monitoring infrastructure with prometheus
Monitoring infrastructure with prometheusMonitoring infrastructure with prometheus
Monitoring infrastructure with prometheus
Shahnawaz Saifi
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive Programming
Andres Almiray
 
Design Pattern introduction
Design Pattern introductionDesign Pattern introduction
Design Pattern introduction
neuros
 

What's hot (20)

Javascript pour les Développeurs WEB
Javascript pour les Développeurs WEBJavascript pour les Développeurs WEB
Javascript pour les Développeurs WEB
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & Vuex
 
Gestion comptes bancaires Spring boot
Gestion comptes bancaires Spring bootGestion comptes bancaires Spring boot
Gestion comptes bancaires Spring boot
 
Workshop Spring - Session 4 - Spring Batch
Workshop Spring -  Session 4 - Spring BatchWorkshop Spring -  Session 4 - Spring Batch
Workshop Spring - Session 4 - Spring Batch
 
Xen Hypervisor.pptx
Xen Hypervisor.pptxXen Hypervisor.pptx
Xen Hypervisor.pptx
 
Javascript Prototype Visualized
Javascript Prototype VisualizedJavascript Prototype Visualized
Javascript Prototype Visualized
 
Cours javascript v1
Cours javascript v1Cours javascript v1
Cours javascript v1
 
JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿JSP 프로그래밍 #03 서블릿
JSP 프로그래밍 #03 서블릿
 
JHipster on AWS
JHipster on AWSJHipster on AWS
JHipster on AWS
 
An Introduction to OpenCL™ Programming with AMD GPUs - AMD & Acceleware Webinar
An Introduction to OpenCL™ Programming with AMD GPUs - AMD & Acceleware WebinarAn Introduction to OpenCL™ Programming with AMD GPUs - AMD & Acceleware Webinar
An Introduction to OpenCL™ Programming with AMD GPUs - AMD & Acceleware Webinar
 
Introduction to Reactive programming
Introduction to Reactive programmingIntroduction to Reactive programming
Introduction to Reactive programming
 
The virtual DOM and how react uses it internally
The virtual DOM and how react uses it internallyThe virtual DOM and how react uses it internally
The virtual DOM and how react uses it internally
 
Spring Framework Petclinic sample application
Spring Framework Petclinic sample applicationSpring Framework Petclinic sample application
Spring Framework Petclinic sample application
 
Concevoir, développer et sécuriser des micro-services avec Spring Boot
Concevoir, développer et sécuriser des micro-services avec Spring BootConcevoir, développer et sécuriser des micro-services avec Spring Boot
Concevoir, développer et sécuriser des micro-services avec Spring Boot
 
Support JEE Spring Inversion de Controle IOC et Spring MVC
Support JEE Spring Inversion de Controle IOC et Spring MVCSupport JEE Spring Inversion de Controle IOC et Spring MVC
Support JEE Spring Inversion de Controle IOC et Spring MVC
 
WEB SERVICE SOAP, JAVA, XML, JAXWS
WEB SERVICE SOAP, JAVA, XML, JAXWSWEB SERVICE SOAP, JAVA, XML, JAXWS
WEB SERVICE SOAP, JAVA, XML, JAXWS
 
Vert.x for Microservices Architecture
Vert.x for Microservices ArchitectureVert.x for Microservices Architecture
Vert.x for Microservices Architecture
 
Monitoring infrastructure with prometheus
Monitoring infrastructure with prometheusMonitoring infrastructure with prometheus
Monitoring infrastructure with prometheus
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive Programming
 
Design Pattern introduction
Design Pattern introductionDesign Pattern introduction
Design Pattern introduction
 

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 JavaScript
kvangork
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascript
kvangork
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
Ankit Rastogi
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event Sourcing
Samuel ROZE
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
jeresig
 
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
 
JavaScript Refactoring
JavaScript RefactoringJavaScript Refactoring
JavaScript Refactoring
Krzysztof Szafranek
 
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
 
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
 
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 Programmers
David Rodenas
 
MVI - Managing State The Kotlin Way
MVI - Managing State The Kotlin WayMVI - Managing State The Kotlin Way
MVI - Managing State The Kotlin Way
Zeyad Gasser
 
Google App Engine Developer - Day3
Google App Engine Developer - Day3Google App Engine Developer - Day3
Google App Engine Developer - Day3
Simon Su
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbroncymbron
 
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
 
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
jbarciauskas
 
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
Martin Zapletal
 

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
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event Sourcing
 
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
 
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
 
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
 
MVI - Managing State The Kotlin Way
MVI - Managing State The Kotlin WayMVI - Managing State The Kotlin Way
MVI - Managing State The Kotlin Way
 
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
 
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
 
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
 

Recently uploaded

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
UiPathCommunity
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
Globus
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 

Recently uploaded (20)

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..UiPath Community Day Dubai: AI at Work..
UiPath Community Day Dubai: AI at Work..
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Enhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZEnhancing Performance with Globus and the Science DMZ
Enhancing Performance with Globus and the Science DMZ
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 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