Monday, June 11, 2012

Programmatically add custom event in the iPhone Calendar


Is there any way to add iCal event to the iPhone Calendar from the custom App?



Source: Tips4all

5 comments:

  1. You can do this using the Event Kit framework in OS 4.0.

    Right click on the FrameWorks group in the Groups and Files Navigator on the left of the window. Select 'Add' then 'Existing FrameWorks' then 'EventKit.Framework'.

    Then you should be able to add events with code like this:

    //
    // EventTestViewController.m
    // EventTest
    //
    // Created by Some Person on 5/07/10.
    // Copyright __MyCompanyName__ 2010. All rights reserved.
    //

    #import "EventTestViewController.h"
    #import <EventKit/EventKit.h>

    @implementation EventTestViewController

    - (void)viewDidLoad {
    [super viewDidLoad];

    EKEventStore *eventStore = [[EKEventStore alloc] init];

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



    - (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
    }

    - (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    }


    - (void)dealloc {
    [super dealloc];
    }

    @end

    ReplyDelete
  2. Yes there still is no API for this (2.1). But it seemed like at WWDC a lot of people were already interested in the functionality (including myself) and the recommendation was to go to the below site and create a feature request for this. If there is enough of an interest, they might end up moving the ICal.framework to the public SDK.

    https://developer.apple.com/bugreporter/

    ReplyDelete
  3. Calendar access is being added in iPhone OS 4.0:


    Calendar Access
    Apps can now create and edit events directly in the
    Calendar app with Event Kit.
    Create recurring events, set up start and end
    times and assign them to any calendar
    on the device.

    ReplyDelete
  4. Currenctly there is no API for manipulating calendars from your own application on the phone. There is an API for the address book.

    Anyone know if this is going to be addressed?

    ReplyDelete
  5. The Google idea is a nice one, but has problems.

    I can successfully open a Google calendar event screen - but only on the main desktop version, and it doesn't display properly on iPhone Safari. The Google mobile calendar, which does display properly on Safari, doesn't seem to work with the API to add events.

    For the moment, I can't see a good way out of this one.

    ReplyDelete