3

I wrote the following snippet to create an event. Setting the alarm works fine in iOS 4, but in iOS 5 it doesn't get set. Is this a bug or am I missing something?

EKCalendar *cal = [self.eventStore defaultCalendarForNewEvents];
EKEvent *event = [EKEvent eventWithEventStore:self.eventStore];
event.calendar = cal;
// .......
EKAlarm *alarm = [EKAlarm alarmWithRelativeOffset:-3600];
event.alarms = [NSArray arrayWithObject:alarm];
// .......
jscs
  • 63,694
  • 13
  • 151
  • 195
Alexander
  • 1,495
  • 2
  • 19
  • 24

3 Answers3

3

I had the same error.

The problem seems that startDate shoudln't be the same as endDate... really silly iOS change!

phy
  • 31
  • 1
  • whoa.. this helped me out in ios7.1 too, for reference I was getting a `NSError` with `Code=29` in `EKErrorDomain` about "unable to modify alarms" which is also not documented. – Gianluca P. Jun 12 '14 at 15:32
1

It seems to be related to that's happening in this ticket: EventKit - App freezes when adding an EKEvent with 2 alarms (iOS 5).

If you take a look at the EventKit section in the iOS 5 changes from iOS 4.3 document, it mentions that some items are deprecated for EKEvent. The hierarchy has changed and a new abstract superclass has been added: EKCalendarItem.

Community
  • 1
  • 1
ruxy
  • 282
  • 3
  • 9
0

Avoid manipulating the alarms array. You need to add the alarm to your event like this:

EKAlarm *reminder = [EKAlarm alarmWithRelativeOffset:-300];
[event addAlarm:reminder];

This will add a reminder 5 minutes before the start time.

Julio Bailon
  • 3,735
  • 2
  • 33
  • 34