IOS9 How to create a reminder in the Calendar app that starts before a casual time (iii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.