First, open the System app
1. Open the calendar:
If Uiapplication.sharedapplication (). Canopenurl (Nsurl (string: "Calshow:")!) {
Uiapplication.sharedapplication (). OpenURL (Nsurl (string: "Calshow:")!)
}
2, open the reminder item:
If Uiapplication.sharedapplication (). Canopenurl (Nsurl (string: "x-apple-reminder://")!) {
Uiapplication.sharedapplication (). OpenURL (Nsurl (string: "x-apple-reminder://")!)
}
Ii. add information to your system's calendar or reminders:
1. Add an event to your calendar:
(1), create event drive:
Let Eventstore = Ekeventstore ()
(2), authorized access to the calendar:
Eventstore.requestaccesstoentitytype (. Event) {(result, erro) in}
(3), edit event:
Let event = ekevent (EventStore:self.eventStore)
Event name
Event.title = "Reminder"//Event name
Event.notes = "Notes Your Sister"//Event notes
Event location
Event.location = "Dongsheng Science Park"
This setting is true when the start end time is not displayed
Event.allday = True
Start time
Event.startdate = NSDate ()
End time
Event.enddate = NSDate (timeintervalsincenow:3600)
Event.addalarm (Ekalarm (relativeoffset: -60*15))//Set reminders
Must set: System's Calendar
Event.calendar = self.eventStore.defaultCalendarForNewEvents
(4), add event:
do {
Let _ = Try Self.eventStore.saveEvent (event, Span:. Thisevent)
} catch {
Print (Error)
}
2. Add an event to a matter:
(1), create event drive:
Let Eventstore = Ekeventstore ()
(2), Authorized access reminders:
Eventstore.requestaccesstoentitytype (. Reminder) {(result, erro) in}
(3), Editorial matters:
Let Reminde = Ekreminder (EventStore:self.eventStore)
Event name
Reminde.title = "Test Reminder"
Place of Event
Reminde.location = "Dongsheng Science Park"
Item Level: 1-9,1 Highest
reminde.priority = 1
reminde.notes = "Test test testing test test"
Item Start Event
Let start = Nsdatecomponents ()
Start.day = 5
Start.year = 2016
Start.month = 9
Start.hour = 22
Start.minute = 30
Start.timezone = Nstimezone.systemtimezone ()
Reminde.startdatecomponents = Start
Event End Events
Let end = Nsdatecomponents ()
End.day = 8
End.year = 2016
End.month = 9
End.hour = 23
End.minute = 30
End.timezone = Nstimezone.localtimezone ()
Reminde.duedatecomponents = End
Description
The end time is set and only the end time is displayed in the event and the start time is not displayed
Reminde.addalarm (Ekalarm (relativeoffset: -60*15))//Add Reminder time
Must be set: The default reminder app
Reminde.calendar = Self.eventStore.defaultCalendarForNewReminders ()
(4), add items:
do {
Let _ = Try Self.eventStore.saveReminder (Reminde, Commit:true)
} catch {
Print (Error)
}
Third, find the system calendar or reminders in the information:
1. Find Calendar events:
(1), create event drive:
Let Eventstore = Ekeventstore ()
(2), authorized access to the calendar:
Eventstore.requestaccesstoentitytype (. Event) {(result, erro) in}
(3), find event:
1), create a Find condition
Let predicate = self.eventStore.predicateForEvents (Withstart:date (timeintervalsincenow: -3600), End:date (), Calendars:nil)
2), using conditions to find: Because it is thread synchronization, time consuming, it is recommended to operate on other threads
Find Method 1:
Let events = Self.eventStore.events (matching:predicate)
Find Method 2: Every found one will call closure
Self.eventStore.enumerateEvents (Matching:predicate, using: {(Event,pointer) in})
2. Find Reminders:
(1), create event drive:
Let Eventstore = Ekeventstore ()
(2), Authorized access reminders:
Eventstore.requestaccesstoentitytype (. Reminder) {(result, erro) in}
(3), find event:
1), create a Find condition
Get all the conditions of the event
Let pre0 = Self.eventStore.predicateForReminders (In:nil)
Items not completed within the specified time
Let Pre1 = Self.eventStore.predicateForIncompleteReminders (Withduedatestarting:date (timeintervalsincenow:3600), Ending:date (timeintervalsincenow:3600), Calendars:nil)
Conditions that have been completed within the specified time
Let Pre2 = Self.eventStore.predicateForCompletedReminders (Withcompletiondatestarting:date (timeintervalsincenow:- 3600), Ending:date (timeintervalsincenow:3600), Calendars:nil)
2), using conditions to find: Because it is thread synchronization, time consuming, it is recommended to operate on other threads
Get things
Let _ = Self.eventStore.fetchReminders (matching:pre0, Completion: {(reminders) in})
Iv. Delete the system's calendar or reminders in the event information:
1. Delete Calendar events:
do {
Let _ = Try Self.eventStore.remove (event, span:. Thisevent)
} catch {
Print (Error)
}
2. Tips for deleting items:
do {
Let _ = Try Self.eventStore.remove (reminders?. FIRST)!, Commit:true)
} catch {
Print (Error)
}
System calendars and reminders for calls and interactions (Swift)