In my app, I am fetching EKEventStore for events and saving them locally in CoreData for the very first time when user runs the app. For this point on i only want to fetch events from EventStore when there is any changes in the event store.
I used EKEventStoreChangedNotification and it works fine when ever i add an event in the calendar while my app is in background. But it doesn't work when the app is closed.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.eventStore = [[EKEventStore alloc]init];
[self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(storeChanged:)
name:EKEventStoreChangedNotification
object:self.eventStore];
}
}];
return YES;
}
-(void)storeChanged:(NSNotification *)notif {
// Update core data
}