Last active
November 28, 2018 11:15
-
-
Save ajayjapan/efea668a39d7674d85f8ff39bea4424b to your computer and use it in GitHub Desktop.
UNLocationNotificationTrigger Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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