transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.63k stars 425 forks source link

Location Permission "Always" not shown in iOS 14 settings. #1168

Closed pepesrz91 closed 3 years ago

pepesrz91 commented 3 years ago

Your Environment

We set up our info.plist with the following configurations:

Expected Behavior

The app must show in iOS 14 the option of allow "Always" both in the settings configuration of the app and in the second pop up of location permissions introduced in iOS 13.

The app is working as expected in all other aspects, if we start a freeway drive, the simulator triggers the corresponding event handlers correctly when the app is in the Foreground. The same is true when using a iOS device.

Actual Behavior

We don't get the option "Always" in settings and the second pop up requesting the user to allow location "Always" is never triggered. The app locations events are not being triggered when it is in the Background.

Steps to Reproduce

Just try it in an iOS 14 device.

Context

We want to use the geofences and location events while the app is in the background.

We don't know if Apple has changed the actual permissions, we noticed that some location services APIs changed in both Obj-C and Swift. The best article we have found so far regarding this issue for extra context is the following:

https://medium.com/better-programming/handling-location-permissions-in-ios-14-2cdd411d3cca

Thanks for the help!

Debug logs

Logs ``` PASTE_YOUR_LOGS_HERE ```
pepesrz91 commented 3 years ago

So we got it working

Changed the config as example in docs:

 BackgroundGeolocation.ready(
      {
        debug: false,
        logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
        desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
        distanceFilter: 10,
        url: 'www.example.com',
        autoSync: true,
        stopOnTerminate: false,
        startOnBoot: true,
      },
      state => {
        console.log(
          '- BackgroundGeolocation is configured and ready: ',
          state.enabled,
        );

        if (!state.enabled) {
          BackgroundGeolocation.start(function() {
            console.log('- Start success');
          });
        }
      },
    );

I don't think the above config caused the error, but another more subtle issue.

[Incorrect]: In the Info.plist we had this configuration :

image

If you notice, string is in a white color, meaning there is a typo in the key Privacy - Location Always and When in Use Usage Description

[Correct]: We corrected the typo ( which was a space at the end of Privacy - Location Always and When in Use Usage Description ), then it looks like this:

image

You can notice that the string character is now the same gray color as the other keys. With this change everything works as expected. A pretty dumb mistake that just wasted our time, I hope this helps anyone to avoid having the same issue.

What I think is important to show is that the permission:

Is not mentioned in the docs, and I think it is important to add that in Info.plist so that the plugin works well in iOS 14.

Thanks to anyone who took the time in checking this out.

stephen776 commented 3 years ago

I've got this same issue even after verifying there are no typos in my info.plist entries. (I actually had the same one you did but the issue remains after fixing)

When I start my app in the iOS simulator(iPad), I get the initial location permission prompt with the options of "allow once" or "allow while using app" which I believe is expected.

However I never get a follow up. dialog to change to "Always". Once my app starts receiving location updates, I get the following modal dialog:

image

If I cancel, my app UI appears to be locked up. components will re-render but I can't click anything as if a modal background is still blocking things.

If I choose to go Settings, the "Always" option is still not present.

my plist values are as fllows:

image

@christocracy christocracy Can we re-open this? I've been through the docs and tried many different config options but can't get past this.

christocracy commented 3 years ago

Plugin version?

stephen776 commented 3 years ago

Plugin version?

3.9.3

christocracy commented 3 years ago

iOS only allows your app to show the "Upgrade to Always" dialog once.

Go to Settings->Privacy->Location Services->Your app and reset to [Ask Next time].

stephen776 commented 3 years ago

When I change the the setting to Ask Next Time and re-launch the app, I get the permissions dialog as expected (see below) image

But after that, I get no second dialog re: the "always" permissions and I get the "Background location is not enabled" shotly after

Here's my current config for reference:

image

changing debug to false or true makes no difference and doesn't give me any additional clues

christocracy commented 3 years ago

Try installing the SampleApp on your device.

stephen776 commented 3 years ago

The sample app seems to work fine. I get the "always" prompt almost immediately after the initial prompt

stephen776 commented 3 years ago

Ok, I figured it out. I compared the Info.plist from my app and sample and I was missing:

        <key>NSLocationTemporaryUsageDescriptionDictionary</key>
    <dict>
        <key>DemoPurpose</key>
        <string>CHANGEME:  Allow the sample app to track location with high accuracy</string>
    </dict>

This appears to be important for showing the secondary "always" modal