ios 日历事件

EventKit框架

iOS 4.0引入了EventKit框架 (EventKit.framework)。此框架为访问用户设备的日历事件提供接口。您可以通过该框架访问用户日历中现有事件,可以增加新事件。日历事件可包含闹铃,而且可以配置闹铃激活规则。

一:using enevt kit

1:get existing events

2:create new events

3:delete events

4:be notified of event changes

二:create new events

1:addEventKit.framework

2:导入头文件

C代码 收藏代码
  1. <fontclass="Apple-style-span"style="font-weight:normal;text-indent:0px;line-height:normal;font-style:normal;white-space:normal;letter-spacing:normal;border-collapse:separate;font-variant:normal;"size="4"color="#000000"><fontclass="Apple-style-span"style="font-size:14px;text-indent:28px;line-height:28px;"color="#333333">#import<EventKit/EventKit.h></font></font>
C代码 收藏代码

C代码 收藏代码

3:

C代码 收藏代码
  1. -(IBAction)createEvent{
  2. //Gettheeventstoreobject
  3. EKEventStore*eventStore=[[EKEventStorealloc]init];
  4. //Createanewevent
  5. EKEvent*event=[EKEventeventWithEventStore:eventStore];
  6. //CreateNSDatestoholdthestartandenddate
  7. NSDate*startDate=[[NSDatealloc]init];
  8. NSDate*endDate=[[NSDatealloc]init];
  9. //Setpropertiesoftheneweventobject
  10. event.title=@"Titlefornewevent";
  11. event.startDate=startDate;
  12. event.endDate=endDate;
  13. event.allDay=YES;
  14. //setevent'scalendartothedefaultcalendar
  15. [eventsetCalendar:[eventStoredefaultCalendarForNewEvents]];
  16. //CreateanNSErrorpointer
  17. NSError*err;
  18. //Savetheevent
  19. [eventStoresaveEvent:eventspan:EKSpanThisEventerror:&err];
  20. //Testforerrors
  21. if(err==noErr){
  22. UIAlertView*alert=[[UIAlertViewalloc]
  23. initWithTitle:@"EventCreated"
  24. message:@"Howaboutthat?"
  25. delegate:nil
  26. cancelButtonTitle:@"Okay"
  27. otherButtonTitles:nil];
  28. [alertshow];
  29. [alertrelease];
  30. }
  31. //Releaseobjects
  32. [startDaterelease];
  33. [endDaterelease];
  34. [eventStorerelease];
  35. }

三:EventKitUI 框架。

在你的app中调用event kit ui

1:导入头文件

C代码 收藏代码
  1. #import<EventKitUI/EventKitUI.h>

@interface CreateEventViewController : UIViewController <EKEventEditViewDelegate>

2:

C代码 收藏代码
  1. -(IBAction)createEvent{
  2. //Gettheeventstoreobject
  3. EKEventStore*eventStore=[[EKEventStorealloc]init];
  4. //CreatetheEditViewController
  5. EKEventEditViewController*controller=[[EKEventEditViewControlleralloc]init];
  6. controller.eventStore=eventStore;
  7. controller.editViewDelegate=self;
  8. [selfpresentModalViewController:controlleranimated:YES];
  9. [controllerrelease];
  10. }

3:delegate method for EKEventEditViewDelegate

C代码 收藏代码
  1. //delegatemethodforEKEventEditViewDelegate
  2. -(void)eventEditViewController:(EKEventEditViewController*)controllerdidCompleteWithAction:(EKEventEditViewAction)action{
  3. [selfdismissModalViewControllerAnimated:YES];
  4. }

你可能感兴趣的:(ios)