按钮到日历中的事件

时间:2012-03-07 17:06:10

标签: iphone xcode

我想制作一个按钮,在iPhone上的日历中添加一个事件。

示例:

点击此按钮,您的日历中将显示一个事件,显示Superbowl的时间和日期。 (或其他东西)

希望有些人可以帮助我。

由于

2 个答案:

答案 0 :(得分:1)

add 2 frameworks
1.EventKitUI.framework
2.EventKit.framework

.m
#import <EventKitUI/EventKitUI.h>

- (IBAction)CreateEvent:(id)sender {

    //Get the even store object
    //EKEventStore *eventStore = [[EKEventStore alloc] init];
    EKEventStore *eventStore = [[EKEventStore alloc] init];

    /* iOS 6 requires the user grant your application access to the Event Stores */


     if([[UIDevice currentDevice].systemVersion floatValue] >= 6.0)// checks if device is ios6
       {
    [eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) {
        // handle access here
    }];





    if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
    {
        // iOS Settings > Privacy > Calendars > MY APP > ENABLE | DISABLE 
        [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
         {
             if ( granted )
             {
                 NSLog(@"User has granted permission!");
             }
             else
             {
                 NSLog(@"User has not granted permission!");
             }
         }];
    }



           EKEventEditViewController *controller=[[EKEventEditViewController alloc]init];


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

    }


    else
    {


    EKEventEditViewController *controller=[[EKEventEditViewController alloc]init];


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

    }
}



- (void)eventEditViewController:(EKEventEditViewController *)controller didCompleteWithAction:(EKEventEditViewAction)action
{
  //  [Bw alert:@"Done"];


    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" Done" message:@"Event Sucessfully Saved " delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
    [alert show];

    [self dismissModalViewControllerAnimated:YES];

}





@end

答案 1 :(得分:0)

有许多不同的路线可以获得相同的结果,但是一个好的起点可能是this tutorial,这解释了一种完全相同的方法。