将文本从UIViewController附加到内置的iphone日历

时间:2014-02-05 06:19:38

标签: ios calendar reminders

在我的应用程序中,我需要在UIButton动作上附加(显示iphone内置日历)内置iphone日历。更多,来自我的UIViewController s UILabel, I need attach that text in iphone的文本在内置日历中作为提醒,用户可以根据需要自由选择日期。 我发现像EventKIt框架可能对我有用,但我不确定。我也不熟悉EventKit框架。

1 个答案:

答案 0 :(得分:1)

将此示例与EventKit框架一起使用。

    -(IBAction)buttonAction:(id)sender
    {

        EKEventStore *eventStore = [[EKEventStore alloc] init];
        EKEventStore *eventStore = [[[EKEventStore alloc] init] autorelease];
        if([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])                {
            // iOS 6 and later
            [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
                if (granted){
                    //---- codes here when user allow your app to access theirs' calendar.
                    [self performCalendarActivity:eventStore];
                }else
                {
                    //----- codes here when user NOT allow your app to access the calendar.
                }
            }];
        }
         else {
                    //---- codes here for IOS < 6.0.
                    [self performCalendarActivity:eventStore];
        }           

    }

-(void)performCalendarActivity:(EKEventStore *)eventStore 

{
    EKEvent *event  = [EKEvent eventWithEventStore:eventStore];
    event.title     = @"EVENT TITLE";
event.startDate = [[NSDate alloc] init];
event.endDate   = [[NSDate alloc] initWithTimeInterval:600  sinceDate:event.startDate];
    [event setCalendar:[eventStore defaultCalendarForNewEvents]];
            NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
}

不要忘记将#import <EventKit/EventKit.h>导入视图控制器。