Skip to content

Instantly share code, notes, and snippets.

@ajayjapan
Last active November 28, 2018 11:15
Show Gist options
  • Save ajayjapan/efea668a39d7674d85f8ff39bea4424b to your computer and use it in GitHub Desktop.
Save ajayjapan/efea668a39d7674d85f8ff39bea4424b to your computer and use it in GitHub Desktop.
UNLocationNotificationTrigger Example
// Define the content of the notification
let content = UNMutableNotificationContent()
content.title = place.title
content.body = place.blurb
content.sound = UNNotificationSound.default()
// Define the region
let region = CLCircularRegion(center: place.coordinate(), radius: place.radius ?? 100, identifier: place.identifier)
region.notifyOnEntry = true
region.notifyOnExit = false
// Define the trigger
let trigger = UNLocationNotificationTrigger(region: region, repeats: false)
// Define the request
let request = UNNotificationRequest(identifier: place.identifier, content: content, trigger: trigger)
// Add the request
let center = UNUserNotificationCenter.current()
center.add(request, withCompletionHandler: { (error) in
if let error = error {
print("\n\t ERROR: \(error)")
} else {
print("\n\t request fulfilled \(request)")
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment