I have a seemingly straightforward, textbook case of using EventKit to create events with alarms. Frustratingly, it doesn't work. Here's what I'm doing:
- Create an
EKEvent
with[EKEvent eventWithEventStore:]
and fill out a bunch of its properties - Add an alarm with
[myEvent addAlarm:[EKAlarm alarmWithRelativeOffset:]]
- Save the event with
[myEventStore saveEvent:span:error:]
The only "unusual" things about the whole process is that I'm using a phone with an older iOS version (iOS4.3.3 on an iPhone 4), and that all the calendars I'm using are synced to Google Calendars.
I have one calendar (let's call it CalendarA) that's set up in Google Calendars to have an automatic 30-minute alarm for new events, and another calendar (CalendarB) that's not set up for any automatic alarms.
Here's the broken behaviour I'm seeing:
- When I add an
EKAlarm
with some sort of non-zero relativeOffset (e.g. 5 minutes) to CalendarA, the calendar ignores my offset and sets it to 30 minutes - When I do the same thing in CalendarB, my alarm gets ignored completely, and the event ends up having no alarm
What's really strange: If I set relativeOffset to zero, everything works perfectly well for that special case! (A zero-offset alarm is correctly added, both in the CalendarA and CalendarB cases). By the way, if I don't create an alarm at all, events in CalendarA still get a 30-minute alarm. I guess there's nothing that can be done about this.
I've also tried saving the event right after event creation, and then right away adding an alarm to the already-saved instance and saving it again. This didn't help.
If I manually create events with alarms through the native Calendar app on the phone, alarms work perfectly well, so I know that it is possible to sync arbitrary alarms to Google Calendars - the question is how to do it through code.
How can I make my event alarms behave correctly?