How to create a reminder to start at any time in the Calendar app in iOS9 (i)

Source: Internet
Author: User

Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
If you feel that the writing is not good please more advice, if you feel good please support a lot of praise. Thank you! Hopy;)

We know that if you want to create an alarm start time in the Calendar app that comes with iOS, you can only select one from a few values:

After the selection is complete the following status:

What if we have special timing requirements? For example, we want to order an alarm 7 seconds before the start of the calendar event.

Below this cat will take you to complete this function step-by-step.

I. Get calendar read-write permission

First of all you need to know that if you want the operating system calendar database, we must obtain the corresponding permissions:

Ekeventstore *eventstore = [Ekeventstore new];Switch([Ekeventstore authorizationstatusforentitytype:ekentitytypeevent]) { CaseEkauthorizationstatusauthorized://We have obtained the desired permission             Break; CaseEkauthorizationstatusdenied: [ SelfDisplayaccessdenied]; Break; Caseekauthorizationstatusnotdetermined:{[Eventstore requestaccesstoentitytype:ekentitytypeevent completion:^ (BOOLGranted,Nserror*error) {if(granted) {//user now permits us to read and write calendar database}Else{                    [ SelfDisplayaccessdenied]; }            }]; Break; } Caseekauthorizationstatusrestricted: [ SelfDisplayaccessrestricted]; Break;default: Break; }

Note that we are using the Ekeventstore Authorizationstatusforentitytype: Class method, And get permission we're using Ekeventstore's example method Requestaccesstoentitytype: Don't confuse that.
The Eventstore instance variable in the code above can be understood as an abstraction of the calendar database. You may ask why you want to create an instance variable without a singleton object? One possibility is that iOS might want to access the calendar in a way that is thread safe.

Two. Find the corresponding calendar source

Next we need to find a specific calendar source, which is an instance object of Eksource. Calendar source You can understand that some groups are categorized by calendar type. For example, in the following simulator:

We can see that the calendar database consists of 2 calendar sources, default and other. Would you say that the first source name is not called on MY iphone? What do you mean by default? This is not a hurry, We'll go to the origin of the default name in the code that follows, as long as you know that the name of the first calendar source displayed in is not the real name, it is mostly an alias that is set to make it easier for the user to understand.

Another example of a real machine:

You can see that the slices are from the iphone6p (iOS9.2.1), where the first calendar source name is icloud, which includes many calendars. We must keep in mind that a single iOS device (or Mac device) can have several Apple IDs, each apple The ID of the calendar database can have several calendar sources, each calendar source can have a number of calendars.

Of course you can also enumerate calendars without a calendar source, and you can enumerate the calendars in the specified Ekeventstore instance directly:

Nsarray*calendartypes = @[@"Local",@"CalDAV",@"Exchange",@"Subscription",@"Birthday"];Nsarray*calendars = [Store calendarsforentitytype:ekentitytypeevent]; Nsuinteger i =1; for(Ekcalendar *calendar in calendars) {NSLog(@"Calendar%lu Title =%@",(unsigned Long) I,calendar. Title);NSLog(@"Calendar%lu Type =%@",(unsigned Long) I,calendartypes[calendar. Type]);NSLog(@"Calendar%lu Color =%@",(unsigned Long) i,[UicolorColorwithcgcolor:calendar. Cgcolor]);if([Calendar Allowscontentmodifications]) {NSLog(@"Calendar%lu can be modified.",(unsigned Long) (i); }Else{NSLog(@"Calendar%lu cannot be modified.",(unsigned Long) (i);    } i++; }

If you think it's quicker to locate the calendar this way, then ok! that's fine. But let's look at another way to enumerate calendars from a specified calendar source, goodbye to the next chapter.

How to create a reminder to start at any time in the Calendar app in iOS9 (i)

Related Article

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.