The EKEventStoreChangedNotification will only fire when your app comes to the foreground. However if you want to call your storeChanged: method in the background, and thus having the UI already updated on coming to foreground again, you need to add the Background Fetch capability to your app.
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
</array>
In your app delegate didFinishLaunchingWithOptions method add the line
[application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];
This ensures your app actually calls your background fetch, as the default interval is never. This minimum key is the key that ensures iOS handles when to call your background fetch method. You can set your own minimum interval if you don't want it to fire as often as possible.
Finally implement the background fetch method in your app delegate:
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
[self storeChanged:nil];
completionHandler(UIBackgroundFetchResultNewData);
}
You can test in Xcode while debugging from Debug > Simulate Background Fetch.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…