1
votes

I am using (Always Allow) location permission in my iOS Xamarin Forms application. The problem I face today is that I'm unable to fully leverage ALWAYS permission in order to bring back my app (which was already killed) in the background whenever a location event occurs. Any Solution for that ?

My Code :

lm = new CLLocationManager
           {
               PausesLocationUpdatesAutomatically = false,
               DesiredAccuracy=CLLocation.AccuracyBest,
               DistanceFilter=0,
               AllowsBackgroundLocationUpdates = true
           };


           lm.LocationsUpdated +=
               (object sender, CLLocationsUpdatedEventArgs e) => {
                   var locations = e.Locations; 
                   LocationEventArgs args = new LocationEventArgs();
                   args.lat = locations[locations.Length - 1].Coordinate.Latitude;
                   args.lng = locations[locations.Length - 1].Coordinate.Longitude;
                   locationObtained(this, args);  //Log
               };
           lm.AuthorizationChanged += (object sender,
               CLAuthorizationChangedEventArgs e) => {
                   if (e.Status == CLAuthorizationStatus.Authorized)
                   {
                       //lm.StartMonitoringSignificantLocationChanges();
                       lm.StartUpdatingLocation();
                   }
               };
           lm.RequestAlwaysAuthorization();

Thank you

1

1 Answers

0
votes

The problem I face today is that I'm unable to fully leverage ALWAYS permission in order to bring back my app (which was already killed) in the background whenever a location event occurs.

If APP terminated , AllowsBackgroundLocationUpdates will not work. You should ensure app is not killed first.

allowsBackgroundLocationUpdates : A Boolean value indicating whether the app should receive location updates when suspended.(Not killed status).