Event Kit architecture

SimpleEKDemo is an example sample code project that utilizes events in Event Kit.

不论是 Events 还是remainder 都是存储在 calendar database中,统一用类EKEventStore检索,

EKEventStore *store = [[EKEventStore alloc] init];

ios6中,加入权限:因此要用来判断是否有权限访问EKEntityTypeEvent ,EKEntityTypeReminder,

[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {

// handle access here

}];

Fetching events with a predicate

// Get the appropriate calendar
NSCalendar *calendar = [NSCalendar currentCalendar];
 
// Create the start date components
NSDateComponents *oneDayAgoComponents = [[NSDateComponents alloc] init];
oneDayAgoComponents.day = -1;
NSDate *oneDayAgo = [calendar dateByAddingComponents:oneDayAgoComponents
                                              toDate:[NSDate date]
                                             options:0];
 
// Create the end date components
NSDateComponents *oneYearFromNowComponents = [[NSDateComponents alloc] init];
oneYearFromNowComponents.year = 1;
NSDate *oneYearFromNow = [calendar dateByAddingComponents:oneYearFromNowComponents
                                                   toDate:[NSDate date]
                                                  options:0];
 
// Create the predicate from the event store's instance method
NSPredicate *predicate = [store predicateForEventsWithStartDate:oneDayAgo
                                                        endDate:oneYearFromNow
                                                      calendars:nil];
 
// Fetch all events that match the predicate
NSArray *events = [store eventsMatchingPredicate:predicate];

Retrieving Reminders

You can call fetchRemindersMatchingPredicate:completion: to access multiple reminders that match a predicate. Pass a predicate returned by one of the following methods:

  • predicateForIncompleteRemindersWithDueDateStarting:ending:calendars: finds incomplete reminders within an optional time period

  • predicateForCompletedRemindersWithCompletionDateStarting:ending:calendars: finds completed reminders within an optional time period

  • predicateForRemindersInCalendars: finds all reminders

NSPredicate *predicate = [store predicateForRemindersInCalendars:nil];
 
[store fetchRemindersMatchingPredicate:predicate completion:^(NSArray *reminders) {
    for (EKReminder *reminder in reminders) {
        // do something for each reminder
    }
}];

calendarItemWithIdentifier: can fetch any calendar item (reminders and events), whereas eventWithIdentifier: fetches only events.

Observing External Changes to the Calendar Database

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(storeChanged:)
                                             name:EKEventStoreChangedNotification
                                           object:eventStore];

The Event Kit UI framework provides two types of view controllers for manipulating events:

  • EKEventViewController: use this class if you have an existing event you want to display.

  • EKEventEditViewController: use this class to allow the user to create, edit, or delete events.

EKEventViewController *eventViewController = [[EKEventViewController alloc] init];
eventViewController.event = myEvent;
eventViewController.allowsEditing = YES;
navigationController = [[UINavigationController alloc] initWithRootViewController:eventViewController];
EKEventEditViewController* controller = [[EKEventEditViewController alloc] init];
controller.eventStore = myEventStore;
controller.editViewDelegate = self;
[self presentModalViewController:controller animated:YES];

- (void)eventEditViewController:(EKEventEditViewController *)controller

didCompleteWithAction:(EKEventEditViewAction)action {

NSError *error = nil;

EKEvent *thisEvent = controller.event;

switch (action) {

case EKEventEditViewActionCanceled:

// Edit action canceled, do nothing.

break;

case EKEventEditViewActionSaved:

// When user hit "Done" button, save the newly created event to the event store,

// and reload table view.

// If the new event is being added to the default calendar, then update its

// eventsList.

if (self.defaultCalendar ==  thisEvent.calendar) {

[self.eventsList addObject:thisEvent];

}

[controller.eventStore saveEvent:controller.event span:EKSpanThisEvent error:&error];

[self.tableView reloadData];

break;

case EKEventEditViewActionDeleted:

// When deleting an event, remove the event from the event store,

// and reload table view.

// If deleting an event from the currenly default calendar, then update its

// eventsList.

if (self.defaultCalendar ==  thisEvent.calendar) {

[self.eventsList removeObject:thisEvent];

}

[controller.eventStore removeEvent:thisEvent span:EKSpanThisEvent error:&error];

[self.tableView reloadData];

break;

default:

break;

}

// Dismiss the modal view controller

[controller dismissModalViewControllerAnimated:YES];

}

Calendars and Reminders相关推荐

  1. iOS10---新特性以及适配点

    iOS 10新特性以及适配点 SiriKit 所有第三方应用都可以用Siri,支持音频.视频.消息发送接收.搜索照片.预订行程.管理锻炼等 Proactive Suggestions系统预先建议 背景 ...

  2. calendar 5 android版,calendars 5 安卓

    Calendars 5介绍 Calendars 5 is complete re-imagining of what the best mobile calendar experience shoul ...

  3. SharePoint 2013/2010 中的日历重合 (Calendars Overlay)

    本文介绍 SharePoint 2013/2010 中的日历重合 (Calendars Overlay). 日历重合 (Calendars Overlay)的用途就是将 不多于10个日历或日历视图聚集 ...

  4. android 根据时间获取周几_android 调用系统 calendars 如何获取一个指定日期的所有日程 event。...

    android 调用系统 (CalendarContract)calendars 如何获取一个指定日期的所有日程(包含周期事件) ? 难点在于,很多event存的时候是有rrule的,也就是周期. 以 ...

  5. Apache Pivot教程 -- Calendars

    Apache Pivot教程 – Calendars package calendar;import org.apache.pivot.wtk.*; import org.apache.pivot.c ...

  6. calendar 5 android版,Calendars 5 by Readdle

    编辑点评 在日历上进行行程管理 Calendars 5 by Readdle 介绍 Calendars 5 by Readdle Calendars 5 重新设计界面,造就最佳日历应用体验. Cale ...

  7. 第五章第二十九题(显示日历)(Display calendars)

    第五章第二十九题(显示日历)(Display calendars) **5.29(显示日历)编写程序,提示用户输入年份和代表该年的第一天是星期几的数字,然后在控制台上显示该年的日历表.例如,如果用户输 ...

  8. Calendars and DateFormats should not be static

    "Calendars" and "DateFormats" should not be static 级别:bug, multi-threading Not a ...

  9. 日历提醒软件Export Calendars Pro for Mac

    Export Calendars Pro for Mac是一款非常不错的日历提醒软件,通过Export Calendars Pro Mac您还可以导出几乎任何通讯录字段附加到事件,Export Cal ...

  10. Calendars - 日历插件

    Calendars - 日历插件 1)jQuery Frontier Calendar是一个可灵活定制的月日历jQuery插件,看起来类似于Google Calendar.当在一个日期单元格中有比较多 ...

最新文章

  1. 【SSH进阶之路】Hibernate映射——一对一单向关联映射(五)
  2. uwsgi指定python路径_uwsgi-安装实操
  3. Oracle 时区(TimeZone )-- DST
  4. linux 查看hadoop命令大全,linux下hadoop集群常用命令
  5. 【转载】qsort 与 bsearch 的魔力
  6. MySQL优化步骤和my.cnf优化配置
  7. php json输出后 u6563,肉肉's Blog
  8. mysql之给字段设置缺省值
  9. 出现—passwd:Authentication token manipulation error—错误的解决办法
  10. 睡后收入:小白的自动赚钱神器
  11. 还原android系统文件夹,如何从Android的内存中恢复文件-万兴恢复专家
  12. 智云通CRM:如何发现高附加值客户,让他们直接按原价购买?
  13. 痞子衡嵌入式:串口调试工具Jays-PyCOM诞生记(2)- 界面构建(wxFormBuilder3.8.0)
  14. 无间狱无服务器信息,无间狱打不动了,分享一些想法(不开99流),多图
  15. PTA寒假基础题训练(含解题思路)(中)
  16. 网吧母盘制作其本流程
  17. 关于备案问题 免费帮您解决备案问题 该网站暂时无法访问 尊敬的用户,您好很抱歉,该网站暂时无法访问,可能由以下原因导致: 原因一:未备案或未接入;根据《非经营性互联网信息服务备案管理办法》,网站需要完
  18. 晶振PPM指标、频率和时间偏差
  19. 因为我们正试图把许多的期待留给春
  20. Python读取excel表格人员数据同时批量写入多个excel个人登记表

热门文章

  1. if scl.shape = avg.shape: AttributeError: ‘float‘ object has no attribute ‘shape‘
  2. 微信小程序制作背景图片
  3. 超详细的程序员未来职业发展路线
  4. brew install/update过程中download failed的问题及解决方法 2016年01月21日 10:29:23 strawman_dxj 阅读数:6013 标签: brew in
  5. Js/html格式化在线工具
  6. PT100恒流源测温电路【一】
  7. 中国文学通史之各个阶段介绍
  8. 二项式展开推广与微积分的关系
  9. virtualbox win10 共享文件夹
  10. 停车场管理系统php设计,停车场管理系统设计源代码