I'm writing my first iOS app (I'm tired of missing event reminders and want to have a rule based reminder that, for example for certain calendars and certain people, will ring a different, louder tone, 10, 5 and 0 minutes before the event)
The first part is to get access to the calendar, and thanks to this great demo, I have that sort of covered. Got the app running on my iPhone and I can see my calendar events.
(well, the first part is to figure out swift, and general iOS basic, which I'm still working on)
The second part is where I wanted to ask before I spend hours researching. I have two tasks left to do
either a background task to periodically check the calendar for new/updated events, or ability to programmatically subscribe to some sort of an event bus any calendar updates (new events, event changes)
schedule notifications on a given time (I'll probably use this: How can I schedule local notification for the following scenario?)
How do I accomplish #1?
I don’t think this is possible to accomplish without a design change.
Applications do not generally run in the background, and outside of very specific cases where Apple allows it (voip, music, location, etc.), your application will be suspended. There is the background refresh API, but that is not reliable enough.
Note that EKEventStoreChangedNotification
notifications are only good when your process is running. If your process dies (due to memory pressure, device reboot, user killing the app, etc.), you will not be notified about changes when the app is launched, and you will still have to iterate over the meetings and look for changes, so you have to develop your own mechanism to iterate the EventKit database (perhaps within a certain timeframe).
If it’s a personal app, there are some tricks you can do to continue running in the background, such as playing a silent music file, voip background API, location, etc.). All these methods can keep your app running in the background, but will take a toll on battery life, and will not be approved by Apple upon submission. One way to have a consistent background runtime is to have a push notification service set a silent push to wake the app up periodically, and let it do its logic. This has the potential to launch the app in case it has been killed in the background (but not if the user killed it).