Vatsal Bhatt
Vatsal Bhatt

Reputation: 1

iOS - Geofencing Event Not Triggering When App is Killed and Not Opened After 2-3 Days

I’m facing an issue with geofencing events in my app. When the app is killed and not opened for 2–3 days, the geofencing event is not triggering when I re-enter the geofenced area. I’ve made sure that all necessary permissions (location, background refresh, etc.) are properly set in the app settings. Has anyone else experienced this? Is there a solution or workaround to ensure that geofencing works as expected even after the app has been killed for several days?

startMonitoringSignificantLocationChanges also mentioned in applicationWillTerminate Method.

func createRegion(latitude :Double , longitude : Double, radius : Double) {

    let dateFormatter =  DateFormatter()
    dateFormatter.dateFormat = "dd/MM/yyyy HH:mm:ss"
    let date = dateFormatter.string(from: Date())
    let geofenceRegionCenter = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
    let geofenceRegion = CLCircularRegion(center: geofenceRegionCenter, radius: radius, identifier: "First")
    geofenceRegion.notifyOnEntry = true
    geofenceRegion.notifyOnExit = true
    locationManager.startMonitoring(for: geofenceRegion)
}


func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {

    let dateFormatter =  DateFormatter()
    dateFormatter.dateFormat = "dd/MM/yyyy HH:mm:ss"
    let date = dateFormatter.string(from: Date())
    self.isEnter =  true
    let latitude = manager.location?.coordinate.latitude ?? 0.00
    let longitude = manager.location?.coordinate.longitude ?? 0.00
}
   
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {

   let dateFormatter =  DateFormatter()
   dateFormatter.dateFormat = "dd/MM/yyyy HH:mm:ss"
   let date = dateFormatter.string(from: Date())
   self.isEnter =  false
   let latitude = manager.location?.coordinate.latitude ?? 0.00
   let longitude = manager.location?.coordinate.longitude ?? 0.00
}

Upvotes: 0

Views: 58

Answers (0)

Related Questions