Where can I find a good tutorial on IOS Calender s

2019-05-22 14:50发布

问题:

I am working on an iPhone app.

How to sync new events with iOS Calendar?

回答1:

You can go-through this github code this will really help you if you want to syn with events in calander of you app...

https://github.com/klazuka/Kal

Hope this will solve your problem...

Another one:-

For implementing the calander and for synchronization with data of calander you have to implement the calander by adding the Event Frame work in your code :-

EventKitUI.framework

EventKit.framework

Add these two frameworks after adding these frame you have to update ur viewController in which you have to giving the option of update the calander or Alarm option for calander.

import these two in your .h file

#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>

EKEventEditViewDelegate protocol,

make the objects of these classes

EKEventViewController *detailViewController;
EKEventStore *eventStore;
EKCalendar *defaultCalendar;
NSMutableArray *eventsList;

and make @property 's and @synthesize then

make one method for addEvents in calander

-(IBAction) addEvent:(id)sender;

then after doing this go to .m file

@synthesize the properties.

in your viewDidLoad method added these :-

    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;
}

now i think you understand the code... Thanks....