Does region monitoring still works when app forced killed?

I have this code that works fine on fore and background but the didExitRegion event will not call when I force killed the app. The springboard shows the geofencing location icon but nothing will come in. Am I missing something?

Any comments are greatly appreciated.

I have the appropriate background mode "

App registers for location updates
& "
Privacy - Location Always Usage Description
in info.plist.




let regionMgr = CLLocationManager()


var didUpdateLocation = false


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { / setAppAppearances() checkNetworkReachability() / if CLLocationManager.authorizationStatus() == .authorizedAlways { setlocationSettings() } } return true }


func setlocationSettings() { regionMgr.requestAlwaysAuthorization() regionMgr.stopMonitoringAllRegions() regionMgr.allowsBackgroundLocationUpdates = true regionMgr.desiredAccuracy = kCLLocationAccuracyHundredMeters regionMgr.activityType = CLActivityType.fitness regionMgr.delegate = self regionMgr.requestLocation() }


func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { kLastLocation = locations.last! let lat = String(describing: kLastLocation.coordinate.latitude) let long = String(describing: kLastLocation.coordinate.longitude) if didUpdateLocation != true { NSLog("didUpdateLocations appDelegate") DispatchQueue.main.asyncAfter(deadline: delayTime(1.0)) { sendTrajectories(long, lat) } didUpdateLocation = true setlocationSettings() / self.createRegion(kLastLocation) } else { NSLog("updated location again and again lol"); regionMgr.stopUpdatingLocation() } }


func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { print("error:: \(error.localizedDescription)") }


func createRegion(_ loc:CLLocation?) { if CLLocationManager.isMonitoringAvailable(for: CLCircularRegion.self) { let coordinate = CLLocationCoordinate2DMake((loc?.coordinate.latitude)!, (loc?.coordinate.longitude)!) let regionRadius = 100.0 / let region = CLCircularRegion(center: CLLocationCoordinate2D( latitude: coordinate.latitude, longitude: coordinate.longitude), radius: regionRadius, identifier: "region") region.notifyOnExit = true region.notifyOnEntry = true / NSLog("createRegion called") / if CLLocationManager.authorizationStatus() == .authorizedAlways { setlocationSettings() regionMgr.distanceFilter = 100 regionMgr.startMonitoring(for: region) NSLog("startMonitoring \(region)") } } else { print("system can't track regions") } }


func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion) { NSLog("didStartMonitoringForRegion"); regionMgr.requestStateForRegion(region); }


func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error) { NSLog("Region monitoring failed with error: \(error.localizedDescription)") }


func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) { NSLog("Entered Region") }


func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) { NSLog("Exited Region") / / setlocationSettings() didUpdateLocation = false / regionMgr.requestLocation() regionMgr.startUpdatingLocation() }

What process did you use to force kill?


Power off the device...remove from recents...delete off device...code a crash? Simulator or device?

If you "force quit" an app, iOS will not relaunch it in any of the otherwise automatic scenarios until you manually relaunch the app. Don't "force quit" an app that you want to have relaunched for you.


If geofencing is still showing, you should file a bug report, because the 'do not launch' behavior is going to prevent anything from happening.

I always thought it will relaunch the app based on the documentation below. Not sure if I am missing something.


The apple docs said:

In most cases, the system does not relaunch apps after they are force quit by the user. One exception is location apps, which in iOS 8 and later are relaunched after being force quit by the user. In other cases, though, the user must launch the app explicitly or reboot the device before the app can be launched automatically into the background by the system. When password protection is enabled on the device, the system does not launch an app in the background before the user first unlocks the device.

https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

As far as I can tell, your code is turns off region monitoring when it gets relaunched.


I know for regular background location relaunches, you have to be careful when you re-register and re-initialize otherwise the app won't receive the notifications after being relaunched. I assume the same applies to region monitoring.

Does region monitoring still works when app forced killed?
 
 
Q