Adding events to calendar in ios 5 programatically

13,398

Solution 1

The code is correct and works in iOS 5. The reason for my error was the first line

eventStore=[[EKEventStore alloc] init];

Since initializing eventstore takes some time, placing it in application launch method resulted in time out. I found it from my crash report stating:

"Elapsed application CPU time (seconds):30 seconds"

The app is supposed to launch within 10 seconds. if not time out occurs with Exception Codes: 0x8badf00d

Solution 2

You have to use 5th version of SDK. You can find a diff in saveEvent function:

[eventStore saveEvent:addEvent span:EKSpanThisEvent commit:YES error:nil]; 

It should help you.

Share:
13,398
NaveenaRK
Author by

NaveenaRK

Updated on June 04, 2022

Comments

  • NaveenaRK
    NaveenaRK almost 2 years
    eventStore=[[EKEventStore alloc] init];
    EKEvent *addEvent=[EKEvent eventWithEventStore:eventStore];
    addEvent.title=@"hello";
    addEvent.startDate=messageDate;
    addEvent.endDate=[addEvent.startDate dateByAddingTimeInterval:600];
    [addEvent setCalendar:[eventStore defaultCalendarForNewEvents]];
    addEvent.alarms=[NSArray arrayWithObject:[EKAlarm alarmWithAbsoluteDate:addEvent.startDate]];
    [eventStore saveEvent:addEvent span:EKSpanThisEvent error:nil];
    

    The code above works fine in ios 4.2 but not in ios 5. I have the code in applicationDidfinishingLaunching method. Due to error, black screen appears and app exits. Only recurrenceRules has changed in ios 5 and I have not made use of it. All other properties are available in superclass EKCalendarItem. I cannot test it since I have xcode 3.2 and snow leopard. I am looking to debug the line at which error occurs causing the app to quit. I doubt it is related to setCalendar or using alarms property.