CLLocationManager Region Monitoring: Detect Arrival in Suspended State
Any location update/monitoring requires it's location manager to be configured properly so that it can work to the best to provide the desired location update. It's important to check some point when doing background location update:
1. Check background modes of location updates and background fetch should be enable
2. Check 'Location Always Usage Description' and 'Location When in Use Usage Description' in the Info.plist should be provided
3. Check if you want to pause in between location update - if yes then you need to provide activity type so that location manager can determine best way to pause location update for you
4. Check if you want to apply distance filter - you want user(device) to move some minimum amount for location manager to send updated location
5. Check if you want desired accuracy- This may cause power drain for certain accuracy type
In your code I can see location manager is configured with some of the parameter but missing accuracy and distance filter for background mode.
locationManager.allowsBackgroundLocationUpdates = true
locationManager.pausesLocationUpdatesAutomatically = false
locationManager.activityType = .otherNavigation
Also, if you see pause location update property in Apple doc it says:
For apps that have in-use authorization, a pause to location updates
ends access to location changes until the app is launched again and
able to restart those updates. If you do not wish location updates to
stop entirely, consider disabling this property and changing location
accuracy to kCLLocationAccuracyThreeKilometers when your app moves to
the background. Doing so allows you to continue receiving location
updates in a power-friendly manner.
Essentially it tells that if you want disable pause then you have to keep accuracy level (kCLLocationAccuracyThreeKilometers). Which I guess is missing in your approach.
Also, you can check this link which actually starts background task and then starts location manager monitoring inside the background task.
Hope it helps.
startMonitoringForRegion is not calling didEnterRegion if the app is started within the region
I don't think you can do that.
But, you can get the current location and check if it's inside the region you're specifying yourself. CLCircularRegion
has a containsCoordinate:
method for this.
Will geofencing events be called if the app is terminated in iOS 11?
After running many tests, I can confirm that Geofence Events are called, even when the app is terminated (swipe up). However, the user must have authorized location to be used when the app isn't running, and other background location functions, such as didUpdateLocation
will not be called.
Related Topics
Union Uibezierpaths Rather Than Apend Path
How to Logout User Using Facebook Authentication Using Swift and iOS
Are View Controllers with Nib Files Broken in iOS 8 Beta 5
Weird Behaviour of Xcode 11 Debugger - Showing Values as Nil When There's a Value
Convert an Nsurl to an Nsstring
What Does Get-Task-Allow Do in Xcode
How to Change the Height of a Uinavigationbar in Storyboard Without Using a Uinavigationcontroller
Storyboard Reference in Xcode, Where Should We Use It
How to Add a Button with Click Event on Uitableviewcell in Swift
Deploying an iOS Application Using Apple Enterprise Developer Program
Swiftui - Animations Triggered Inside a View That's in a List Doesn't Animate the List as Well
Xcode 4.2: How to Import .H File from Subproject
Error: Uicollectionview Must Be Initialized with a Non-Nil Layout Parameter
Xcode 5.1: Libcordova.A Architecture Problems
Connect Outlet of a Cell Prototype in a Storyboard
How to Make Uiimagepickercontroller for Camera and Photo Library at the Same Time in Swift