Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。












想改善这个问题吗?更新问题,以便将其作为on-topic用于堆栈溢出。

5年前关闭。



Improve this question




我正在使用iPhone应用程序。

如何使用iOS日历同步新事件?

最佳答案

如果您想与应用程序日历中的事件进行同步,则可以遍历此github代码,这确实会对您有帮助...
https://github.com/klazuka/Kal
希望这能解决您的问题...
另一个:-
为了实现calander并与calander数据同步,您必须通过在代码中添加Event Frame工作来实现calander:

EventKitUI.framework
EventKit.framework

添加这些框架后,添加这两个框架,您必须更新ur viewController,在其中必须提供更新calander的选项或calander的Alarm选项。
将这两个导入到您的.h文件中

#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>
EKEventEditViewDelegate协议,
制作这些类的对象
EKEventViewController *detailViewController;
EKEventStore *eventStore;
EKCalendar *defaultCalendar;
NSMutableArray *eventsList;
然后使@property和@synthesize
在calander中为addEvents做一个方法
-(IBAction) addEvent:(id)sender;
然后执行此操作后转到.m文件
@synthesize属性。
在您的viewDidLoad方法中添加了以下这些:
    self.eventStore = [[EKEventStore alloc] init];


    self.eventsList = [[NSMutableArray alloc] initWithArray:0];

    // Get the default calendar from store.
    self.defaultCalendar = [self.eventStore defaultCalendarForNewEvents];

    // create an Add button
    UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"bell.png" ] style:UIBarButtonItemStylePlain target:self action:@selector(addEvent:)];
    //UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(addEvent:)];
    self.navigationItem.rightBarButtonItem = addButtonItem;
    [addButtonItem release];


and added this...

    #pragma mark -

#pragma mark Add a new Event
-(IBAction) addEvent:(id)sender {

    self.eventStore = [[EKEventStore alloc] init];
    EKEvent *event = [EKEvent eventWithEventStore:eventStore];
  //  event.title =@"Whatever you want your title to be";
    event.title = self.currentTitle;

//    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    event.allDay = YES;

    EKEventEditViewController *addController = [[EKEventEditViewController alloc] initWithNibName:nil bundle:nil];
    addController.event = event;
    addController.eventStore = self.eventStore;
    [self presentModalViewController:addController animated:YES];

    addController.editViewDelegate = self;
    [addController release];

}


#pragma mark -
#pragma mark EKEventEditViewDelegate

// Overriding EKEventEditViewDelegate method to update event store according to user actions.
- (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];

}


// Set the calendar edited by EKEventEditViewController to our chosen calendar - the default calendar.
- (EKCalendar *)eventEditViewControllerDefaultCalendarForNewEvents:(EKEventEditViewController *)controller {
    EKCalendar *calendarForEdit = self.defaultCalendar;
    return calendarForEdit;
}
现在我想你了解代码了...
谢谢....

08-03 13:58