cordova-plugin-background-geolocation icon indicating copy to clipboard operation
cordova-plugin-background-geolocation copied to clipboard

iOS 13.1 Beta - Geolocation not reported when app is in background

Open grabkipower opened this issue 6 years ago • 18 comments

Seems like the geolocation is not reported when the app runs in background despite the "Always" permission is set

Your Environment

  • Plugin version: 3.0.6
  • Platform: iOS 13.1 beta
  • OS version:
  • Device manufacturer and model: IPhone 6s
  • Cordova version (cordova -v): 9.0.0 (cordova-lib 9.0.1)
  • Cordova platform version (cordova platform ls): ios 5.0.1
  • Plugin configuration options:
  • Link to your project:

Context

On iOS 13.1 when the user has checked in the settings of the app the "always" permission for the iOS, the location is not beeing recorded after one leaves the app (switches the app to background i.e.).

I can see that on the navtive Cordova Background Geolocation It this issue has been already raised and solved: transistorsoft/cordova-background-geolocation-lt#952

Expected Behavior

The Geolocation should be properly sent even if the app is in the background

Steps to Reproduce

  1. Turn on the "Always" geolocation permission (turned on from the settings page, not from the prompt - as it is no longer available in the iOS 13).
  2. Start tracking the geolocation
  3. Go to the desktop
  4. After approx. 30 seconds the location arrow on the top bar will disappear and the geolocation requests will cease beeing sent to the server.
  5. Going back to the application reenables sending of the geolocation requests

grabkipower avatar Sep 09 '19 15:09 grabkipower

@mauron85 I am sorry for being pushy, but do you have a clue about this one? iOS 13 releases tomorrow, there might be a great impact if the background geoloc report would not work in the background. For now, the issue still persists.

grabkipower avatar Sep 18 '19 10:09 grabkipower

It seems to be a general issue with iOS 13.

  • You dont get (not every time, but sometimes, cant say explicit when) the blue tracking icon
  • If the new authority confirm box (Only in foreground, Once, Never) you got BackgroundGeolocation.AUTHORIZED, if the user select "only in foreground". -- So the trackings stops in background without any response or callback etc. If you resume the app, you got the question from ios if you allowed every time in background and the tracking jumps from the last point in foreground to the current point

But i dont have any idea atm to solve the issue :/

busaku avatar Sep 23 '19 13:09 busaku

@busaku Mhm, thank you for the reply, well, at least I am not the only one fighting this bug.

grabkipower avatar Sep 24 '19 09:09 grabkipower

Is seems the issue happens only with ACTIVITY_PROVIDER, when using RAW_PROVIDER (and app has proper permissions) geolocation in background works fine.

tkondej avatar Oct 04 '19 13:10 tkondej

Hello @tkondej how to change that setting?

aamir-munir avatar Oct 04 '19 17:10 aamir-munir

@itcurves simply by specifying locationProvider, check the example https://github.com/mauron85/cordova-plugin-background-geolocation#example

tkondej avatar Oct 07 '19 09:10 tkondej

@tkondej, I'm still having issues with background data sending to my server using RAW_PROVIDER - I currently use DISTANCE_FILTER_PROVIDER but I switched to RAW_PROVIDER for testing. Both fail. I was wondering if you could explain what you mean by "and app has proper permissions". My app used to work prior to IOS13 so I was wondering if there is a new permission required for IOS13?

stgraham2000 avatar Nov 04 '19 10:11 stgraham2000

@stgraham2000 on iOS 13 you have to enable access to use "geolocation always" in application settings or by accepting additional prompt which popups when after locking and unlocking the phone, check this article for more details https://medium.com/@transistorsoft/ios-13-and-android-q-support-beb7595d2c24

tkondej avatar Nov 04 '19 10:11 tkondej

@tkondej, interesting, I had the "always on" under permissions for most of the day and it appeared to be broken, but it looks like another thing to look out for is you need to go for a longer distance test run. In earlier tests today I was probably only walking maybe 50m (around my office). I just tried again by doing a short drive and the points were collected as I expected. Before when I was testing on ios12 I could get points with a much shorter distance travelled. This will be an interesting usability issue to address as the article you referenced also indicates.

It looks like this should still be possible to accomplish location updates while the permissions are set to "while in use":

https://developer.apple.com/documentation/corelocation/getting_the_user_s_location/handling_location_events_in_the_background https://developer.apple.com/documentation/corelocation/cllocationmanager/1620568-allowsbackgroundlocationupdates

I will experiment with this in the morning and report back

stgraham2000 avatar Nov 04 '19 11:11 stgraham2000

Any news? :)

jackie-d avatar Mar 30 '20 19:03 jackie-d

Unfortunately, I took horrible notes on this investigation but I have fixed the problem and here are the changes I have in the commit that fixed this...

  • Went from version 3.0.0-alpha.50 to 3.1.0
  • Following is a snippet of the config changed:
startForeground: true,  # Unset prior
pauseLocationUpdates: false  # Unset prior
stationaryRadius: 10    # Used to be 50
  • Was using this.backgroundGeolocation.finish() at the end of the location handler. I removed these.

I hope one of the above changes works for you. Sorry I can't be of more help.

stgraham2000 avatar Mar 30 '20 20:03 stgraham2000

Hello, please look at my posts #684

In your config.xml be sure to add the following configuration under the iOs platform xml node:

        <config-file parent="UIBackgroundModes" target="*-Info.plist">
            <array>
                <string>fetch</string>
            </array>
            <array>
                <string>location</string>
            </array>
            <array>
                <string>processing</string>
            </array>
        </config-file>
        <edit-config file="*-Info.plist" mode="merge" target="NSLocationWhenInUseUsageDescription">
            <string>need location access to find things nearby</string>
        </edit-config>

that's equivalent to the following setup from Xcode

77958309-26a26980-72d5-11ea-8812-96afeb264aa5

jackie-d avatar Apr 01 '20 07:04 jackie-d

@jackie-d - Give a try to this plugin-

https://www.npmjs.com/package/cordova-plugin-bg-geolocation https://github.com/Anuj-Raghuvanshi/cordova-plugin-bg-geolocation

This works, Thanks!

anujraghuvanshi avatar Apr 25 '20 21:04 anujraghuvanshi

I have finally got this to work on a real device! the key change: locationProvider: BackgroundGeolocation.RAW_PROVIDER i,e, do NOT use ACTIVITY_PROVIDER as shown in the geolocation example in the docs as this doe NOT work in the background on IOS devices as explained here https://github.com/mauron85/cordova-plugin-background-geolocation/blob/HEAD/PROVIDERS.md

I am not sure the settings mentioned above are also required in the config.xml file under the 'ios platform' sectio. I suspect the default already set by the plugin (i.e. 'location') might be sufficient.

tfelici avatar Sep 11 '20 07:09 tfelici

@tfelici - Can you please share reference of your plugin if you have forked and made changes? I also facing same issue.

Anuj-logiciel avatar Sep 11 '20 11:09 Anuj-logiciel

I have not done any fork. I am using the vanilla 3.1.0 version

Kind regards

Tom On 11/09/2020 12:05, Anuj Singh wrote:

@tfelici https://github.com/tfelici - Can you please share reference of your plugin if you have forked and made changes? I also facing same issue.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mauron85/cordova-plugin-background-geolocation/issues/619#issuecomment-691029600, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB2PYTFAC43VNIMXLF3LQC3SFH76BANCNFSM4IU5AYGQ.

tfelici avatar Sep 11 '20 11:09 tfelici

ok - after further tests I can confirm this woks on IOS 13.7 on my daughter's iphone and ipad. Here are the relevant settings in BackgroundGeolocation.configure

BackgroundGeolocation.configure({
	locationProvider: BackgroundGeolocation.RAW_PROVIDER,
	desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
	pauseLocationUpdates: false, // need this for IOS I think (default was false anyhow but maybe not)
	stationaryRadius: 20, 
	distanceFilter: 20, // docs say this is dinamically changed when locationProvider = DISTANCE_FILTER_PROVIDER
});

you do NOT need to add the extra lines in config.xml under the IOS platform section

    <config-file parent="UIBackgroundModes" target="*-Info.plist">
        <array>
            <string>location</string>
        </array>
        <array>
            <string>processing</string>
        </array>
    </config-file>

unless you require to app to refresh other stuff in the background, other than location updates and posting

tfelici avatar Sep 11 '20 15:09 tfelici

Hi, there are two ways to works geolocation in background, the first is as you commented with RAW_PROVIDER and the second is setting up in locationProvider: backgroundGeolocation.DISTANCE_FILTER_PROVIDER and call in your event location the method switchMode to force foreground and with this continue reporting in base to option.desiredAccuracy and option.distanceFilter

BackgroundGeolocation.on('location', function(location) { // handle your locations here // switch to FOREGROUND mode BackgroundGeolocation.switchMode(BackgroundGeolocation.FOREGROUND_MODE); })

But I have a question, in the two ways this works and I can see blue in the status bar that means an app is actively using your location. Can this drain the battery? is not sending location until you reach your distance filter but this is always in the status bar. How can I stop showing this status bar in blue? this should show only when I get the location with the icon of location Captura de pantalla 2023-04-23 101538 Below when the app send location Captura de pantalla 2023-04-23 094611 I hope anyone see this.

diegojoel98 avatar Apr 23 '23 16:04 diegojoel98