Background task with Location updates

I am working on a location-based App, In which I need to implement geofencing monitoring for some locations. Geofencing works fine and received notification whenever I enter/exit in a monitored region. Now I need to allow app running for 2 minutes when OS notify us for entering/exit event for the monitored region regardless of App's current state. So that I can verify that the user is still in the region after 2 minutes, then only I need to notify the user for that event. While App is terminated or in the background, and received notification from OS, I register app for UIBackgroundTask to allow app running in background and start a 2 minutes timer. When timer finished, I check for user's location and notify user if he is still in location. Now the issue is at Client Side, When I check UIApplication.shared.backgroundTimeRemaining, It return me arround 40 seconds, while when I run this on my devices, It always return me about 180 seconds. Because of this behaviour, my 2 minutes delayed concept doesn't work and app moved to suspended state before executing 2 min timer. I have confirmed about OS and device, and we are using same device and OS at both side, but still receving different time at both side. I have used below code to register app for background mode func registerBackgroundTask() { backgroundTask = UIApplication.shared.beginBackgroundTask { [weak self] in self?.endBackgroundTask() } } and keeps checking background remaining time with the help of another timer Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { (timer) in ("\(UIApplication.shared.backgroundTimeRemaining) ").writeToLogFile() } Is there any reason because of this, I am receving different remaining times at both side ? Or is there any other way by which I can force app to still remain in active state even background time expires, So that 2 min timer can be fired and after that I terminate background task manually ?

Replies

Hi Shami,

have you got any solution for this problem? I am also facing the same issue, Please share if u find anything.