question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[iOS] User presses while using, getBackgroundPermissionsAsync canAskAgain is true (should be false)

See original GitHub issue

Summary

In my project I am using canAskAgain to determine whether or not to present the system permission dialog if its true, or a link to open Settings if it’s false. This means that if canAskAgain is lying about being TRUE, then the user can get stuck on a screen that can’t present the modal from requestBackgroundPermissionsAsync.

Reproduction steps

  1. Run Location.requestBackgroundPermissionsAsync() and grant “While using”
  2. Log the result of Location.getBackgroundPermissionsAsync():

Result:

{"canAskAgain": true, "expires": "never", "granted": false, "status": "undetermined"}

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

bare

What platform(s) does this occur on?

iOS

SDK Version (managed workflow only)

No response

Environment

Expo CLI 4.1.6 environment info: System: OS: macOS 11.4 Shell: 5.8 - /bin/zsh Binaries: Node: 16.4.0 - /opt/homebrew/bin/node Yarn: 1.22.10 - /opt/homebrew/Cellar/node/16.0.0_1/bin/yarn npm: 7.3.0 - /usr/local/bin/npm Watchman: 2021.06.07.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4 Android SDK: API Levels: 28, 29, 30 Build Tools: 28.0.3, 29.0.2, 30.0.2, 30.0.3 System Images: android-29 | Google APIs Intel x86 Atom_64, android-30 | Google APIs Intel x86 Atom IDEs: Android Studio: 4.2 AI-202.7660.26.42.7351085 Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild npmPackages: @expo/webpack-config: ^0.12.78 => 0.12.81 expo: ^41.0.0 => 41.0.1 react: 16.13.1 => 16.13.1 react-native: 0.63.4 => 0.63.4 Expo Workflow: bare

Reproducible demo or steps to reproduce from a blank project

Reproduction steps

  1. Run Location.requestBackgroundPermissionsAsync() and grant “While using”
  2. Log the result of Location.getBackgroundPermissionsAsync():

Result:

{"canAskAgain": true, "expires": "never", "granted": false, "status": "undetermined"}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jameslopercommented, Jan 20, 2022

Issue is still legit. I’ve made a workaround that is a “lie detector” which I can post below in case it helps anyone. Taken out of context though, so it’s very hard to parse through!

const locationPermission = new PermissionCapability({
	type: 'LOCATION',
	askAsync: Platform.select({
		'ios': Location.requestBackgroundPermissionsAsync,
		'android': Location.requestForegroundPermissionsAsync,
	}),
	checkAsync: async () => {
		const perms = await Location.getBackgroundPermissionsAsync();
		const res = transformExpoPerms(perms);

		if (res.isGranted) {
			res.canAskAgain = false;
			const isPrecise = await isLocationPreciseAsync();
			if (!isPrecise) res.isGranted = false;

			// Check for iOS obtuse design, lying that we have always when we don't
			if (!Storage.get('lieDetected') && locationPermission.status.isUndetermined && res.isGranted) {
				Storage.set('lieDetected', true);
				res.isGranted = false;
			}
		} else {
			const basicPerms = await Location.getForegroundPermissionsAsync(); // another lie detector
			if (basicPerms.granted) res.canAskAgain = false;
		}

		if (res.isGranted) Storage.set('locationPermissionSuccess', true);
		return res;
	},
});
  Expo CLI 5.0.3 environment info:
    System:
      OS: macOS 12.1
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 17.2.0 - /opt/homebrew/bin/node
      Yarn: 1.22.17 - /opt/homebrew/bin/yarn
      npm: 8.1.4 - /opt/homebrew/bin/npm
      Watchman: 2022.01.03.00 - /opt/homebrew/bin/watchman
    Managers:
      CocoaPods: 1.11.2 - /usr/local/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
    IDEs:
      Android Studio: 2020.3 AI-203.7717.56.2031.7935034
      Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
    npmPackages:
      @expo/webpack-config: ^0.16.16 => 0.16.16 
      babel-preset-expo: 9.0.2 => 9.0.2 
      expo: ^43.0.0 => 43.0.5 
      react: 17.0.2 => 17.0.2 
      react-native: 0.64.3 => 0.64.3 
    npmGlobalPackages:
      expo-cli: 5.0.3
    Expo Workflow: bare
0reactions
github-actions[bot]commented, Sep 25, 2022

This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android: canAskAgain from Notifications.getPermissionsAsync ...
For iOS, using Permissions (await Permissions. ... getPermissionsAsync api is returning canAskAgain always true, even when you can't ask ...
Read more >
React native expo iOS cannot ask for background location on ...
Detect if requestForeground.canAskAgain set to true otherwise user has already denied this permission and you can open device setting and user ...
Read more >
Location - Expo Documentation
Location permissions must be granted. On iOS it must be granted with Always option. (iOS only) "location" background mode must be specified in...
Read more >
Asking Permission to Use Notifications - Apple Developer
Request permission to display alerts, play sounds, or badge the app's icon in response to a notification.
Read more >
How to use the expo-permissions.getAsync function in ... - Snyk
To help you get started, we've selected a few expo-permissions.getAsync examples, based on popular ways it is used in public projects.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found