最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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
}
发布评论

评论列表(0)

  1. 暂无评论