-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IOS requestAuthorization doesn't return success or error until you go into the settings and switch the permission value #335
Comments
Don't use that for checking the permission, use this instead: package:https://www.npmjs.com/package/react-native-permissions export const requestAuthorization = async (): Promise<boolean> => {
const permission =
Platform.OS === 'android'
? PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION
: PERMISSIONS.IOS.LOCATION_WHEN_IN_USE;
try {
const result = await check(permission);
if (result === RESULTS.GRANTED) {
return true;
} else if (result === RESULTS.DENIED || result === RESULTS.BLOCKED) {
const requestResult = await request(permission);
return requestResult === RESULTS.GRANTED;
} else {
return false;
}
} catch (err) {
console.warn(err);
return false;
}
}; |
The issue above still exists, I just runned into it today. Same as described, it looks like Even if @stealkiller06 solution works, I don't think that "use another package to do it" is a valid solution. It just adds an extra redundent dependency instead of fixing the real issue.. If this method exists, it must be usable (and used). EDIT: Explanation found After digging up a little bit in the module iOS native code, if found this : In RNCGeolocation.mm, line 284 :
What's going on ?
And so, what is the problem with this ? How to fix this? Solution 1 : Explicitly set the config to force the authorizationLevel to "whenInUse".
Solution 2 : Add the background location capability (see: https://www.npmjs.com/package/@react-native-community/geolocation#requestauthorization:~:text=In%20order%20to%20enable%20geolocation%20in%20the%20background%2C%20you%20need%20to%20include%20the%20%27NSLocationAlwaysUsageDescription%27%20key%20in%20Info.plist%20and%20add%20location%20as%20a%20background%20mode%20in%20the%20%27Capabilities%27%20tab%20in%20Xcode.) Conclusion **EDIT 2: iOS native requestWhenInUseAuthorization() behavior ** @crasyboy42 Your issue is more probably caused by this. The iOS native docs for requestAlwaysAuthorization() tells us :
It means that, on the same run, calling My temporary solution is to fix the package (eg. using patch-package) by replacing line 291 in RNCGeolocation.mm with :
I'll open a PR with this soon, I think its a better behavior as the module doesn't offer any way to check the |
Environment
My machine (windows, build on a mac mini):
The remote server:
Platforms
iOS
Versions
Description
On iOS the .requestAuthorization seems to do nothing until you go into the settings and switch the location permission then suddenly all pending requests are returned in success/error.
Android required me to set locationProvider to playServices but no matter what I try for the iOS configurations I can't get it to call a function normally.
Reproducible Demo
This is the exact code i use in our project and in a clean project. (with moment.js installed for timing)
Info.plist has this key NSLocationWhenInUseUsageDescription but no value
The text was updated successfully, but these errors were encountered: