So I'm currently playing around with EventKit and was trying to get the EKEventStoreChangedNotification to fire when I add/modify/delete calendar entries in the native Calendar app, but after asking permission to access the Calendar, confirming that I'm authorized and signing up for the notification with
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(storeChanged:)
name:EKEventStoreChangedNotification
object:nil];
the selector is never called. Also tried the block syntax, which doesn't work either.
So I figured I'm doing something wrong and found this sample code, which supposedly has working notifications, but even after pulling that project and making sure that the addObserver line is getting called, I haven't been able to see the selector being called when I modify the calendar.
Any ideas how to debug this further?
I think you need to add the eventStore as object. Check this example. Works for me.
Observing External Changes to the Calendar Database
Make sure your
EKEventStore
isn't being deallocated. For example, assign it to a strong property.The following app logs a string when an edit is made in the stock Calendar app:
You have to ensure that
EKEventStore
object stays in memory for use.These scenarios will not work with ARC:
.
This scenarios will work with ARC: