I have subscribed to a location based reminder with the following code:
let center = CLLocationCoordinate2D(latitude: tapp.location.latitude, longitude: tapp.location.longitude)
let region = CLCircularRegion(center: center, radius: CLLocationDistance(tapp.reminder), identifier: tapp.name)
locationManager.distanceFilter = 100
locationManager.startMonitoring(for: region)
region.notifyOnEntry = true
region.notifyOnExit = false
let trigger = UNLocationNotificationTrigger(region: region, repeats: false)
let request = UNNotificationRequest(identifier: "\(tapp.location.latitude)|\(tapp.location.longitude)", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
The code works to remind me when I've entered a region in the iOS simulator, but when I load the app onto a physical device and walk into the region, it never notifies me.
I remember reading something about low power mode affecting whether or not you could subscribe to location based notifications, is there anything else like that which stops the app from receiving background updates? Also, is my code correct?
I am in a similar situation. Location notifications trigger on simulator, tried in foreground, background and closed app state. It triggers in all cases on simulator, but on real device it does not trigger at all in any case, even foreground.
Here is my code for location permission request
And here is my code to request notification permissions
And here is my code to register a location notification
All this works on simulator and doesn't on device...or at least no notification is triggered
BUT I found a workaround that at least in my case works -> Region monitoring
I request always location permission and monitor what regions with locationManager like this
And with the use of the delegate method didEnterRegion I register a notification there and replace the trigger with a time trigger instead of a location trigger
I understand that this is not necessarily a good solution for all, but at least in my case it works. Hopefully it will help others as well