jamesmontemagno / GeolocatorPlugin

Geolocation plugin for Xamarin and Windows
MIT License
294 stars 158 forks source link

[iOS] Blue header when backgrounded #317

Closed padic-dev closed 4 years ago

padic-dev commented 4 years ago

Bug Information

Version Number of Plugin: 4.5.0.6 Device Tested On: iPhone Xr with iOS 13.1.3 Simulator Tested On: N/A Version of VS: 2019 16.3.4 Version of Xamarin: 3.1.0.697729 Versions of other things you are using: Plugin.Permissions 4.0.2-beta

Steps to reproduce the Behavior

  1. Launch my app
  2. Login to enable location listening
  3. Swipe up on bottom handle to send to background

Expected Behavior

After step 3 the top right corner should turn blue with the location arrow indicator.

Actual Behavior

After step 3 the top right corner remains black with time and location arrow indicator to the right of the time.

Code snippet

Upon login the following is run to begin listening: success = await CrossGeolocator.Current.StartListeningAsync(time, distance, false, new ListenerSettings { ActivityType = ActivityType.Other, AllowBackgroundUpdates = true, DeferLocationUpdates = true, DeferralDistanceMeters = distance, DeferralTime = time, ListenForSignificantChanges = true, PauseLocationUpdatesAutomatically = false });

info.plist:

...

UIBackgroundModes location fetch

...

NSLocationWhenInUseUsageDescription [redacted] NSLocationAlwaysUsageDescription [redacted] NSLocationAlwaysAndWhenInUseUsageDescription [redacted]

...

Comments

I can't quite figure out if there is something I am missing and/or doing wrong here to get the standard blue header notification to appear once my app goes into the background while the location listener is active.

I have used logging to verify the listener is working in the background.

If I set the permissions for the app to Location: Always, send it to the background then go into the settings and switch from Location: Always to Location: In Use the blue indicator appears until I bring the app to the foreground. If permissions are set to Location: In Use I cannot get the blue indicator to appear at all. Any advice here?

mzaatar commented 4 years ago

I believe the problem is that the ShowsBackgroundLocationIndicator is being exposed in the ListenerSettings object. It supposed to be exposed.

EDIT: It is actually exposed, what you need to do is to upgrade to "4.6.2-beta" and then you can change your ListenerSettings to include ShowsBackgroundLocationIndicator = true

padic-dev commented 4 years ago

Thanks for the reply, after allowing preleases via the checkbox in VS Nuget Manager I was able to update to 4.6.2-beta then updated my code to:

success = await CrossGeolocator.Current.StartListeningAsync(time, distance, false, new ListenerSettings { ActivityType = ActivityType.Other, AllowBackgroundUpdates = true, DeferLocationUpdates = true, DeferralDistanceMeters = distance, DeferralTime = time, ListenForSignificantChanges = true, PauseLocationUpdatesAutomatically = false, ShowsBackgroundLocationIndicator = true });

Now the indicator properly appears when location is in use while the app is in the background. Closing this issue as it is resolved with this change.