Configuring Alarms
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 Setting Geofences).
Alarms can be applied to both calendar events and reminders.
Attaching and Removing Alarms
You can add an alarm to an event with the addAlarm:
method. 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, set:
The
emailAddress
property to send an emailThe
soundName
property to play a soundThe
url
property to open a URL
You can remove an alarm from an event with the removeAlarm:
method.
Setting Geofences
A geofence is a virtual border surrounding a geographic location that, when crossed, can trigger an alarm for an event. 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 fire that reminds them to stop by the grocery store. As a developer, you have control over specifying the latitude and longitude of the center, as well as the radius of the geofence.
Configure a geofence for an event by creating an alarm and setting its structured location and proximity. Call the locationWithTitle:
method to create a structured location. To set longitude and latitude coordinates, pass a CLLocation
to the geoLocation
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.
While geofence-enabled alarms can be applied to events, they are more practical for reminders.
Copyright © 2016 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2016-09-13