How to remove certain the background location permission from Info.plist?

  1. SDK Version:48
  2. Platforms(Android/iOS/web/all):iOS
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

My app only needs foreground location permission, but expo-location would automatically add NSLocationAlwaysUsageDescription and NSLocationAlwaysAndWhenInUseUsageDescription. I’m able to set the purpose string in app.json or with plugin configuration but I can’t remove them.
I saw some old documentation that says I could put an empty string or null as a value then the key won’t be added but that also doesn’t work after I try.

Hi @swotong

Have a look at these parts of the documentation:

These documentations are specifically for Android and my problem is with Info.plist on iOS? @wodin

Sorry, @swotong I misread your post.

I’ve had a look and I see the documentation has some issues.

  1. The isIosBackgroundLocationEnabled property is not a string, but a boolean value. If you set it to true (or a truthy value) it adds the following to Info.plist:
  1. The locationWhenInUsePermission property is undocumented.

Is it necessary to remove NSLocationAlwaysUsageDescription and NSLocationAlwaysAndWhenInUseUsageDescription?

I would have thought that as long as your Info.plist does not have the UIBackgroundModes section with value location, and you never call useBackgroundPermissions() or getBackgroundPermissionsAsync() and you have a reasonable value for locationWhenInUsePermission it should be fine. Is this not the case?

So I would try something like this:

    "plugins": [
          "locationWhenInUsePermission": "Allow $(PRODUCT_NAME) to use your location when you are using the app.",
          "isIosBackgroundLocationEnabled": false

If you still have problems, maybe you could try adding something like this to the above:

          "locationAlwaysAndWhenInUsePermission": "$(PRODUCT_NAME) does not access your location in the background. If you see this message, contact",
          "locationAlwaysPermission": "$(PRODUCT_NAME) does not access your location in the background. If you see this message, contact",

It will depend on my next app store review’s result whether I have to remove NSLocationAlwaysUsageDescription and NSLocationAlwaysAndWhenInUseUsageDescription given that my app doesn’t need any background location capability. I’ll share the result when I get it. My last submission was rejected because I used this text directly - “Allow $(PRODUCT_NAME) to use your location when you are using the app.” the reviewer told me to change it to be more specific and clear. And they also want me to explain how location service is used by my app’s feature, so I don’t know if they would take it as a problem if these two “always” keys are included in the Info.plist.

Two other things worth mentioning are -

  1. When all these three keys are present, the settings screen would take the description of NSLocationAlwaysAndWhenInUseUsageDescription, so I actually need to add my description to locationAlwaysAndWhenInUsePermission. The system popup prompt doesn’t have such a problem and will use locationWhenInUsePermission.

  2. If an app includes NSLocationAlwaysAndWhenInUseUsageDescription, the settings screen would show the “always” option, otherwise it doesn’t.

As a workaround you could try patch-package with a patch similar to this (untested):

$ cat patches/expo-location+15.1.1.patch

diff --git a/node_modules/expo-location/plugin/build/withLocation.js b/node_modules/expo-location/plugin/build/withLocation.js
index 917f3b0..9d3df2a 100644
--- a/node_modules/expo-location/plugin/build/withLocation.js
+++ b/node_modules/expo-location/plugin/build/withLocation.js
@@ -19,14 +19,8 @@ const withLocation = (config, { locationAlwaysAndWhenInUsePermission, locationAl
         config = withBackgroundLocation(config);
     config = (0, config_plugins_1.withInfoPlist)(config, (config) => {
-        config.modResults.NSLocationAlwaysAndWhenInUseUsageDescription =
-            locationAlwaysAndWhenInUsePermission ||
-                config.modResults.NSLocationAlwaysAndWhenInUseUsageDescription ||
-                LOCATION_USAGE;
-        config.modResults.NSLocationAlwaysUsageDescription =
-            locationAlwaysPermission ||
-                config.modResults.NSLocationAlwaysUsageDescription ||
-                LOCATION_USAGE;
+        delete config.modResults.NSLocationAlwaysAndWhenInUseUsageDescription;
+        delete config.modResults.NSLocationAlwaysUsageDescription;
         config.modResults.NSLocationWhenInUseUsageDescription =
             locationWhenInUsePermission ||
                 config.modResults.NSLocationWhenInUseUsageDescription ||

I would have to test out the functionality to see exactly what’s going on, but I think maybe a proper fix would be to only include the ones mentioned in app.json, except maybe if isIosBackgroundLocationEnabled is true.

This patch works great and is exactly what I need. My app’s working properly without those two ‘always’ keys now and I can report back if there’s any issue.

And I think what you said makes total sense - expo-location should only include NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription if user sets isIosBackgroundLocationEnabled to true.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.