Alert users of events and reminders with an alarm.
An easy way to alert users of their upcoming events is to give them the option of setting alarms for their calendar items. Regardless of the app that’s currently running, alarms come to the foreground as a notification and remind users of the scheduled event. If an alarm is set to a calendar event, the notification comes from the Calendar app; if an alarm is set to a reminder, the notification comes from the Reminders app.
Alarms can be time-based, firing at a specified time, or location-based, firing when crossing a geofence (for more information about geofences, see "Configure Geofences"). Alarms can be applied to both calendar events and reminders.
Add and Remove Alarms
Add an alarm to an event with the
Alarms can be created with an absolute date or with an offset relative to the start date of the event. Alarms created with a relative offset must occur before or at the start date of the event.
In OS X, you can trigger an action alongside the alarm. For example, you can set properties such as:
Remove an alarm from an event with the
A geofence is a virtual border surrounding a geographic location that, when crossed, triggers an alarm for an event. You specify the latitude and longitude of the center and the radius of the geofence.
While geofence-enabled alarms can be applied to events, they are more practical for reminders. Geofences are a useful way to remind users of tasks they need to do when entering or exiting a certain region. For example, when a user leaves their workplace, an alarm can remind them to stop by the grocery store.
Configure a geofence for an event by creating an alarm and setting its structured location and proximity. Call the
init(title:) method to create a structured location. To set longitude and latitude coordinates, pass a
CLLocation to the
geo property of the structured location returned. A value of
0 for the radius property will use the system’s default radius; to choose a radius of your own, specify a value in meters.