React-native-permissions: Requesting Always location is not working

Created on 6 Oct 2019  路  6Comments  路  Source: zoontek/react-native-permissions

Platform: iOS
Device: Simulator iPhoneX, iPhone6
Environment: Xcode 11
React Native: 0.59.10

I have just upgraded to Xcode 11 and the location request for "Always Location" is no longer working. I am getting instead these options displayed:

Allow while using app
Allow Once
Dont Allow

I cant say for 100% but i believe this issue came up with upgrading to Xcode 11, it was working well before, but perhaps the issue is somewhere else. I have tested it on more devices. Here is my code:

requestLocationIos = async() => {
        Permissions.check('location', { type: 'always' }).then(response => {
            if (response != 'authorized') {
                Permissions.request('location', { type: 'always' }).then(response => {
                    if (response != 'authorized') {
                        Alert.alert("Please allow always location in your phone settings")
                        this.getCurrentLocation();
                    }
                    else {
                        this.getCurrentLocation();
                    }
                });
            }
            else {
                this.getCurrentLocation();
            }
        });
    }

Here is my info.plist

        <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>Test needs access to your location.</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>Test needs access to your location.</string>
    <key>NSLocationUsageDescription</key>
    <string>Test needs access to your location.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Test needs access to your location.</string>
invalid

Most helpful comment

@LukePenkava This is not related to this library, but changes introduced with iOS13. Check the "Discussion" paragraph: https://developer.apple.com/documentation/corelocation/cllocationmanager/1620551-requestalwaysauthorization?language=objc

Also read: https://medium.com/q42-engineering/apple-location-permission-ios13-1e0e59002889

This new behavior is a bit weird. If you request LOCATION_ALWAYS, choices will be:

Allow while using app -> "(provisional) always" will be granted, then later a popup will inform the user "this app uses location in background, continue allowing it?"
Allow Once -> "always" will not be granted, but "when in use" will be, then the permission will be reset on next app launch
Dont Allow -> permission blocked

Edit: /example works with RN 0.61.2 + RN-permissions 2.0.1 馃檪, so no problem for the update!

All 6 comments

I have found out that its probably related to ios13 in simulator so i tried to upgrade to react-native-permissions 2.0.1, but i am getting build failed with this error now:

The following build commands failed: CompileC /Users/home/Desktop/APLIKACE/Test/ios/build/Molli/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/ReactNativePermissions.build/Objects-normal/x86_64/RNPNotification.o /Users/home/Desktop/APLIKACE/Test/node_modules/react-native-permissions/ios/Permissions/RNPNotification.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler

It does work but it's a big change as you mention - iOS13 changed things up for location in a big way. I'd do a npx react-native-clean-project clean-project-auto to give your iOS build that sparkly fresh feeling and try again, following the docs carefully

Note that this is very network heavy. If you are on a slow network I still recommend react-native-clean-project but I would specifically run it more like this (I call deep-clean as written in my package.json here during all full builds:

    "deep-clean": "./node_modules/.bin/react-native-clean-project --keep-node-modules --remove-iOS-build --keep-brew --keep-pods --remove-iOS-pods --remove-android-build && yarn clean",
    "clean": "\\rm -fr ./node_modules && \\rm -fr dist/* && \\rm -fr ios/build ios/Pods ios/<YOUR APP NAME>.xcarchive && \\rm -fr android/build android/app/build",

that keeps your brew cache and pods cache but otherwise cleans out the project

@mikehardy thanks for quick reply. I am consider upgrading to RN 0.61 as it seems i will be encountering these issues more frequently because of 0.59.10. Do you think i can expect rn-permissions 2.0.1 work fine on rn 0.61 ?

@LukePenkava it will work significantly better - honestly the jump from RN59 to RN60 was painful but everything is better with it. RN60 to RN61 is a small change, but I wouldn't delay crossing from RN59 to RN60+ personally. After some research last night the only thing that appears troublesome is if you are using react-native-code-push there appear to be a couple workarounds you must do (gleaned from their issue list). No problems with this permissions module though.

@LukePenkava This is not related to this library, but changes introduced with iOS13. Check the "Discussion" paragraph: https://developer.apple.com/documentation/corelocation/cllocationmanager/1620551-requestalwaysauthorization?language=objc

Also read: https://medium.com/q42-engineering/apple-location-permission-ios13-1e0e59002889

This new behavior is a bit weird. If you request LOCATION_ALWAYS, choices will be:

Allow while using app -> "(provisional) always" will be granted, then later a popup will inform the user "this app uses location in background, continue allowing it?"
Allow Once -> "always" will not be granted, but "when in use" will be, then the permission will be reset on next app launch
Dont Allow -> permission blocked

Edit: /example works with RN 0.61.2 + RN-permissions 2.0.1 馃檪, so no problem for the update!

thanks for clarification, i think its good to close now.

Was this page helpful?
0 / 5 - 0 ratings