5 Replies
      Latest reply on Jan 21, 2020 2:48 PM by paul.bln
      mattll Level 1 Level 1 (0 points)
        I am currently testing the background location mode in iOS 13, as I want to track the user´s location and motion (using the CMMotionManager) in the background. Therefore, i have my own (singleton) class handling the location tracking. I initialize the CLLocationManager in the following way:
        func initializeLocationManager() -> CLLocationManager { 
        let manager = locationManager ?? CLLocationManager() 
        manager.delegate = self manager.requestAlwaysAuthorization() 
        manager.allowsBackgroundLocationUpdates = true 
        manager.pausesLocationUpdatesAutomatically = false 
        manager.distanceFilter = kCLDistanceFilterNone 
        manager.desiredAccuracy = kCLLocationAccuracyBest 
        manager.activityType = .other 
        return manager 
        }

        Then I start the following services:  

        func startLocationServices() { 
        ... 
        locationManager.startUpdatingLocation() 
        locationManager.startMonitoringVisits() 
        locationManager.startMonitoringSignificantLocationChanges() 
        ... 
        }

        In addition, I implemented the CLLocationManagerDelegate-methods didChangeAuthorization(), didUpdateLocation().

        In the .plist-file I appended the following entries:<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>

        <string>...</string> 
        <key>NSLocationWhenInUseUsageDescription</key> 
        <string>...</string> 
        <key>UIBackgroundModes</key> 
        <array> 
        <string>location</string> 
        </array> 

        In my view controller, I call the startLocationServices. Currently, I set the app's authorization to track location data to ".authorizedAlways"

        The location updates stop after approximately 60 - 130 minutes.

         

        To solve the problem, I already added the didFinishLaunchingWithOptions-function, which triggers the location-updates again:nc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        if let launchOptions = launchOptions, 
        let isLocationKey = launchOptions[UIApplication.LaunchOptionsKey.location] as? Bool, 
        isLocationKey { 
        restartServices()  
        } 
        return true 
        } 

        When the app gets awoken using this function, I managed to get continuous data on some tests, but sometimes the app was suspended again after a few minutes.

        Last, I also tried a timer that restarts the location tracking every 5 minutes, but this does not seem to affect the update-duration at all.

        I tested the application on iOS 12 and it gets continuous updates in 5/5 tests. So I guess the problem is related to iOS 13.

         

        So my question is if there is a way of continuously receiving the location updates in the background in iOS13, or is there some option I am missing?

        Thanks in advance.

        • Re: Continuous location update background iOS13
          9i9i Level 1 Level 1 (0 points)

          Hey! I got exactly same problem in our app. It typically stopped running in the background not longer than 30 seconds in iOS 13, whereas in iOS 12, it works pretty well in most cases. It seems there’s a bug in the system? Have you figured out any solution?

            • Re: Continuous location update background iOS13
              9i9i Level 1 Level 1 (0 points)

              The same issue happens even though we have switched to Always manually in the settings.

              • Re: Continuous location update background iOS13
                mattll Level 1 Level 1 (0 points)

                Hey! I didnt figure a solution yet. I get around 40 minutes until the app gets suspended. When the "significantLocationChanges" triggers the location updates again, I get just a few minutes/seconds.

                  • Re: Continuous location update background iOS13
                    eito Level 1 Level 1 (0 points)

                    We've started seeing issues since upgrading to iOS 13.3, only on certain devices where location manager doesn't return locations consistently (background or foreground) and will send a number of locations with (0,0) with 2500m accuracy. This was fine before 13.3. Various devices and carriers are exhibiting this behavior.

                     

                    Running an app like Strava on the same phone at the same time, Strava gets locations, our app still doesn't. It is very strange -- made more difficult because it can't be debugging while connected to Xcode in any manner

                      • Re: Continuous location update background iOS13
                        paul.bln Level 1 Level 1 (0 points)

                        Having exactly the same behaviour as mentioned starting with iOS 13.3

                        all good, update get in as expected - then

                        SceneDelegate sceneDidEnterBackground
                        
                        <+52.53865689,+13.42571669> +/- 65.00m (speed -1.00 mps / course -1.00) @ 21.01.20, 23:39:07 Central European Standard Time
                        <+52.53862094,+13.42573375> +/- 65.00m (speed -1.00 mps / course -1.00) @ 21.01.20, 23:39:07 Central European Standard Time
                        <+52.53860520,+13.42569246> +/- 65.00m (speed -1.00 mps / course -1.00) @ 21.01.20, 23:39:09 Central European Standard Time
                        <+52.53878907,+13.42541768> +/- 65.00m (speed -1.00 mps / course -1.00) @ 21.01.20, 23:39:15 Central European Standard Time
                        <+52.52125886,+13.40727788> +/- 2500.00m (speed 0.00 mps / course 0.00) @ 21.01.20, 23:29:42 Central European Standard Time

                        No didUpdateLocations-events following after this 2500 m accuracy location.

                         

                        Is there any workaround known?