Hello,
I'm encountering an issue with UNLocationNotificationTrigger in my iOS app.
I've scheduled three local notifications using UNLocationNotificationTrigger, each tied to a distinct geographic region. These regions are significantly distant from one another and should not trigger simultaneously under normal movement conditions.
However, during testing, the user received all three notifications within one second, despite being physically located near only one of the regions. This behavior is unexpected and defeats the purpose of using location-based triggers.
Could you please clarify why this might be happening? Is there a known issue with UNLocationTrigger, or is there a possibility that iOS preemptively triggers all scheduled location notifications?
Any guidance or recommended practices to avoid this behavior would be greatly appreciated.
Thank you!
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I am trying to retrieve delivered notifications using UNUserNotificationCenter.getDeliveredNotifications(completionHandler:), but I have encountered an issue:
Notifications triggered by UNTimeIntervalNotificationTrigger or UNCalendarNotificationTrigger appear in the delivered list.
However, notifications triggered by UNLocationNotificationTrigger do not appear in the list.
Here is the code I use to fetch delivered notifications:
UNUserNotificationCenter.current().getDeliveredNotifications { notifications in
for notification in notifications {
print("Received notification: \(notification.request.identifier)")
}
}
The notification is scheduled as follows:
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = "Test Notification"
content.body = "This is a location-based notification."
content.sound = .default
let coordinate = CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194) // Example coordinates
let region = CLCircularRegion(center: coordinate, radius: 100, identifier: "TestRegion")
region.notifyOnEntry = true
region.notifyOnExit = false
let trigger = UNLocationNotificationTrigger(region: region, repeats: false)
let request = UNNotificationRequest(identifier: "LocationTest", content: content, trigger: trigger)
center.add(request) { error in
if let error = error {
print("Error adding notification: \(error.localizedDescription)")
}
}
Why does getDeliveredNotifications not return notifications that were triggered using UNLocationNotificationTrigger?
How can I retrieve such notifications after they have been delivered?