I have an application that uses react-native-permissions
. Basically I have a modal regarding location on my App.js
and it will display as long as the user didn't select the "Always allow" option in device settings. It works well on android however modal is always showing in ios simulators knowing that I already selected the "Always allow".
Here's my code:
useEffect(() => {
checkLocationPermission();
}, []);
const checkLocationPermission = async () => {
const permission =
Platform.OS === 'android'
? PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION
: PERMISSIONS.IOS.LOCATION_ALWAYS;
const permissionStatus = await check(permission);
if (
permissionStatus !== RESULTS.GRANTED &&
permissionStatus !== RESULTS.BLOCKED
) {
setCustomModal(true);
}
I tried to console.log(permissionStatus)
and found out that it returns unavailable
Note that I already the following in my info.plist
<key>NSLocationAlwaysUsageDescription</key>
<string></string>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
And in my podfile
permissions_path = '../node_modules/react-native-permissions/ios'
pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse"
So I manage to fix the issue by adding these command in my Podfile
pod 'Permission-LocationWhenInUse', :path => "../node_modules/react-native-permissions/ios/LocationWhenInUse/Permission-LocationWhenInUse.podspec"
pod 'Permission-LocationAlways', :path => "../node_modules/react-native-permissions/ios/LocationAlways/Permission-LocationAlways.podspec"
NOTE: .podspec
file sometimes have different filename depends on the version so make sure to check in node_modules
to avoid pod install
issue.
After applying the code changes I run these commands.
rm -rf /Library/Caches/CocoaPods && rm -rf Pods && rm -rf /Library/Developer/Xcode/DerivedData/* && cd ios && pod cache clean --all && pod deintegrate && pod setup && pod install --verbose && cd ..
And then re run my project.