Skip to content

Instantly share code, notes, and snippets.

@achainan

achainan/example.swift

Last active Nov 28, 2018
Embed
What would you like to do?
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
You can’t perform that action at this time.