0
  1. Run the application
  2. Switch to the background.
  3. “background location update” starts in the background, but it works less than a minute.
  4. I click on the application icon or go back to the application, the "location update" starts working
  5. Go back to the background. "background location update" now works long.

What is the problem? why the first transition to the background mode "background location update" stops working in less than 30 seconds.

public LocationManager()
        {
           this.locMgr = new CLLocationManager
           {
               PausesLocationUpdatesAutomatically = false
           };
           locMgr.AllowsBackgroundLocationUpdates = true;
           locMgr.DesiredAccuracy = 1;
           locMgr.DistanceFilter = 1;
           locMgr.StartUpdatingLocation();
}

my info.plist

<key>UIBackgroundModes</key>
<array>
    <string>location</string>
</array>
<key>NSLocationAlwaysUsageDescription</key>
    <string>This application needs access to a location.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>This application needs access to a location.</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>This application needs access to a location.</string>

my AppDelegate.cs

private CLLocationManager locationManager = new CLLocationManager();
public override void DidEnterBackground(UIApplication application)
        {
            Manager = new LocationManager();
            Manager.StartLocationUpdates();
        }
alexandr f
  • 183
  • 16
  • take a look at: https://stackoverflow.com/questions/52000463/how-to-continue-tracking-location-after-the-user-restarts-the-phone/52001741#52001741 – ingconti Jul 07 '19 at 06:19
  • @ingconti Something there is not clear anything. I did as instructed here https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/ios-backgrounding-walkthroughs/location-walkthrough – alexandr f Jul 07 '19 at 07:06
  • @ingconti Why the first transition to the background mode ends with the fact that "background location update" stops working in less than 30 seconds. If I open the application again, the "background location update" starts up again. And when I go out to the background for the second time, the "background location update" mode works fine, so long. – alexandr f Jul 07 '19 at 07:06
  • I wonder if starting the location manager after the app has already entered background might be too late. I might try (for diagnostic purposes) either `WillResignActive` (slightly earlier in the transition from active-to-background process) or, if that doesn’t work, when the app starts up (ensuring the app is active when the location services are started). – Rob Jul 07 '19 at 18:22
  • @ingconti - That answer is addressing a different issue, significant change service. That’s different than what’s being asked here, the standard background location updates. (Now, if you don’t want destroy the user’s battery and don’t need extremely accurate location updates, then significant change is a preferable option, but that’s a separate question.) – Rob Jul 07 '19 at 18:27
  • Completely unrelated, alexandr, I suspect you know this, but before you submit this to the store, you’ll have to revisit those plist strings. Those strings won’t pass muster with the app review process. ;) – Rob Jul 07 '19 at 18:35

0 Answers0