A trigger condition that causes a notification to be delivered when the user's device enters or exits the specified geographic region.


class UNLocationNotificationTrigger : UNNotificationTrigger


Create a UNLocationNotificationTrigger object when you want to schedule the delivery of a local notification when the device enters or leaves a specific geographic region. The system limits the number of location-based triggers that may be scheduled at the same time.

When configuring the region, use the notifyOnEntry and notifyOnExit properties to specify whether you want notifications to be delivered on entry, on exit, or both. Listing 1 shows the creation of a trigger that fires only once when the user’s device enters a circular region with a 2-kilometer radius.

Listing 1

Creating a location-based trigger

let center = CLLocationCoordinate2D(latitude: 37.335400, longitude: -122.009201)
let region = CLCircularRegion(center: center, radius: 2000.0, identifier: "Headquarters")
region.notifyOnEntry = true
region.notifyOnExit = false
let trigger = UNLocationNotificationTrigger(region: region, repeats: false)

Region-based notifications aren't always triggered immediately when the edge of the boundary is crossed. The system applies heuristics to ensure that the boundary crossing represents a deliberate event and is not the result of spurious location data. For more information about the heuristics that are applied, see Monitoring the User's Proximity to Geographic Regions.


Creating a Location Trigger

init(region: CLRegion, repeats: Bool)

Creates a location trigger for the specified region.

Accessing the Trigger Region

var region: CLRegion

The region used to determine when the notification is sent.


Conforms To

See Also


class UNCalendarNotificationTrigger

A trigger condition that causes a notification to be delivered at a specific date and time.

class UNTimeIntervalNotificationTrigger

A trigger condition that causes a notification to be delivered after the specified amount of time elapses.

class UNPushNotificationTrigger

A trigger condition that indicates the notification was sent from Apple Push Notification Service (APNs).

class UNNotificationTrigger

The common behavior for subclasses that trigger the delivery of a local or remote notification.