ios 4 新特性 日历事件

Event Kit 框架

iOS 4.0引入了 Event Kit框架 (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:add EventKit.framework

 

2:导入头文件

#import <EventKit/EventKit.h>
 

 

 

3:

-(IBAction) createEvent {

 // Get the event store object
 EKEventStore *eventStore = [[EKEventStore alloc] init];
 
 // Create a new event
  EKEvent *event  = [EKEvent eventWithEventStore:eventStore];
 
 // Create NSDates to hold the start and end date
 NSDate *startDate = [[NSDate alloc] init];
 NSDate *endDate  = [[NSDate alloc] init];
 
 // Set properties of the new event object
    event.title     = @"Title for new event";
    event.startDate = startDate;
    event.endDate   = endDate;
    event.allDay = YES;
 
 // set event's calendar to the default calendar
    [event setCalendar:[eventStore defaultCalendarForNewEvents]];
 
 // Create an NSError pointer
     NSError *err;
 
 // Save the event
    [eventStore saveEvent:event span:EKSpanThisEvent error:&err]; 

 // Test for errors
 if (err == noErr) {
  UIAlertView *alert = [[UIAlertView alloc]
         initWithTitle:@"Event Created" 
         message:@"How about that?" 
         delegate:nil
         cancelButtonTitle:@"Okay" 
         otherButtonTitles:nil];
  [alert show];
  [alert release];
 }
 
 // Release objects
 [startDate release];
 [endDate release];
 [eventStore release]; 
}

 三:Event Kit UI 框架。

在你的app中调用event kit ui

 

1:导入头文件

#import <EventKitUI/EventKitUI.h>

 

 

 

 

 

@interface CreateEventViewController : UIViewController <EKEventEditViewDelegate>

2:

-(IBAction) createEvent {
    // Get the event store object
 EKEventStore *eventStore = [[EKEventStore alloc] init];

 // Create the EditViewController
 EKEventEditViewController* controller =[[EKEventEditViewController alloc] init];

    controller.eventStore = eventStore;
    controller.editViewDelegate = self;
 
    [self presentModalViewController: controller animated:YES];
 
    [controller release];

}

 3:delegate method for EKEventEditViewDelegate 

// delegate method for EKEventEditViewDelegate
- (void)eventEditViewController:(EKEventEditViewController *)controller    didCompleteWithAction:(EKEventEditViewAction)action {
    [self dismissModalViewControllerAnimated:YES];
}

 

 

 

你可能感兴趣的:(ios)