Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location tracking stops after a while when app is in the background

I've created a simple app which tracks user location and creates local notification for every time location is updated.

I enabled the background modes below,

enter image description here

let locationManager = CLLocationManager()  open override func viewDidLoad() {        locationManager.delegate = self;        locationManager.desiredAccuracy = kCLLocationAccuracyBest;        locationManager.distanceFilter = 10        locationManager.allowsBackgroundLocationUpdates = true        locationManager.startUpdatingLocation() }  open func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {        let notification = UILocalNotification()        notification.alertBody = "location updated"        notification.fireDate = Date()        UIApplication.shared.scheduleLocalNotification(notification) } 

I set string for NSLocationAlwaysUsageDescription and ask for permission. User grant permission for always usage when the app loaded first time.


It's working well when app is in the foreground, when it goes background still working at least in 5-40 minutes time range which is changeable by battery or other opened apps.

The problem is why it stops working, Isn't it expected to be keep working?

I've never seen a time limit in Apple docs.

like image 624
Okan Kocyigit Avatar asked Aug 11 '17 14:08

Okan Kocyigit


People also ask

How do I keep location services always on?

Click on Create Profile and select Android Profile from the dropdown. Provide the required details and create the profile. Click on Restrictions and select Location settings. For the restriction Location Services, select the option Always On.

Why is my location tracking not working?

You may need to update your Google Maps app, connect to a stronger Wi-Fi signal, recalibrate the app, or check your location services. You can also reinstall the Google Maps app if it isn't working, or simply restart your iPhone or Android phone.

What does it mean when an app uses your location in the background?

Android 10 features a background access location reminder, which increases transparency into how much access apps have to a device's location and helps users maintain control over such access. In Android 9 and lower, an app can track a device's location while running in the background without the user's knowledge.


1 Answers

Switch to significant location updates when the app moves to background. iOS will unload the app if it keep alive in the background indefinitely.

locationManager.pausesLocationUpdatesAutomatically = false 
like image 107
Vimal Saifudin Avatar answered Nov 07 '22 21:11

Vimal Saifudin