SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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 a 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 a 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
 

Último

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 

Último (20)

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 

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