In iOS9, how to create a reminder that starts before any time in the calendar App (1)

Source: Internet
Author: User

In iOS9, how to create a reminder that starts before any time in the calendar App (1)

We know that if you want to create an alert time in the calendar App in iOS, you can only select one of the following values:

The selected status is as follows:

What if we have special timing requirements? For example, how do we set an alarm 7 seconds before a calendar event starts?

Next, we will take you through this function step by step.

1. Get calendar read/write permission

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

EKEventStore * eventStore = [EKEventStore new]; switch ([EKEventStore authorizationStatusForEntityType: EKEntityTypeEvent]) {case when: // we have obtained the desired permission break; case EKAuthorizationStatusDenied: [self displayAccessDenied]; break; case EKAuthorizationStatusNotDetermined: {[eventStore requestAccessToEntityType: EKEntityTypeEvent completion: ^ (BOOL granted, NSError * error) {if (granted) {// The user now permits us to read and write the calendar database} else {[self displayAccessDenied] ;}}]; break ;}case EKAuthorizationStatusRestricted: [self displayAccessRestricted]; break; default: break ;}

Note that the EKEventStore authorizationStatusForEntityType: class method is used to check the license, while the requestAccessToEntityType: Method of the EKEventStore instance is used to obtain the license. Do not confuse this.
The eventStore instance variable in the above Code can be understood as the abstract of the calendar database. You may ask why you need to create an instance variable instead of a singleton object? One possibility is that iOS wants to access the calendar in a thread-safe way.

2. Find the corresponding calendar Source

Next we need to find a specific calendar source, which is an EKSource instance object. The calendar source can be understood as a group that is categorized by calendar type. For example, in the following simulator:

We can see that the calendar database contains two calendar sources: Default and other. Do you mean that the first source name is not on my iphone? Where did the Default come from sometimes? Don't worry, we will go back to the code below to find the origin of the Default name. Now you only need to know that the name displayed in the first calendar is not a real name, most of them are aliases that are easy to understand.

Here is an example of a real machine:

We can see that the film is taken from the iPhone6p (iOS9.2.1) screen. The first calendar name is ICLOUD, which includes many calendars. we must remember that, an iOS device (or Ma ╧ y "http://www.bkjia.com/kf/yidong/wp/" target = "_ blank" class = "keylink"> memory + 49kFwcGxlIElEtcTI1cD6yv2 + 3b/iwO +/memory + Memory + i48L3A + DQo8cD61sci7xOPSsr/ keys + jo8L3A + DQo8cHJlIGNsYXNzPQ = "brush: java; ">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,[UIColor colorWithCGColor: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 is faster to locate the calendar, OK! This is okay. But let's look at another way to enumerate calendars from the specified calendar source.

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.