Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
Assuming that the writing is not good please give more advice, assuming that it is good please support a lot of praise. Thank you! Hopy;)
Four. Create a reminder to start at random time
Now that we've found the specified calendar in the specified source, all that's left to do is create an event in the calendar and set its reminder for it. We are able to create 2 types of events: Single and cyclic (or called repetitive). Here for the sake of simplicity (KISS), we just create a single event:
-(void) Addalarmtocalendar: (ekcalendar*) calendar instore: (ekeventstore*) store{nsdate *startdate = [nsdate Datewithtimeintervalsincenow: -]; NSDate *enddate = [StartDate datebyaddingtimeinterval:.F]; Ekevent *Event= [Ekevent Eventwitheventstore:store];Event. Calendar = Calendar;Event. StartDate = StartDate;Event. endDate = endDate; Ekalarm *alarm = [Ekalarm alarmwithrelativeoffset:-7.F];Event. title =@ "Event with Alarm"; [EventAddalarm:alarm]; Nserror *saveerror = nil;if([Store SaveEvent:EventSpan:ekspanthisevent Error:&saveerror]) {NSLog (@ "Saved an event that fires, seconds from now."); }Else{NSLog (@ "Failed to save the event Error is%@", Saveerror); }}
Let us explain the meaning of the above method:
First set the start and end time of the event.
Then associate the events and calendars. Next, create a reminder object, Ekalarm, and set its start time to the first 7 seconds relative to the start time of the event.
Use the Addalarm: method to associate a reminder with the event object.
Finally, we save the event to the calendar database.
Let's first execute on the simulator:
To be able to see the reminder time is 7 seconds before we finally execute it on the real machine:
Note on a real machine, do not forget to change the calendar source to icloud, and the calendar source to default on the emulator.
IOS9 How to create a reminder in the Calendar app that starts before a casual time (iii)