zoontek / react-native-permissions

An unified permissions API for React Native on iOS, Android and Windows.
MIT License
4.07k stars 830 forks source link

PERMISSIONS.IOS.PHOTO_LIBRARY_ADD_ONLY returns RESULTS.UNAVAILABLE #540

Closed chip-astg closed 3 years ago

chip-astg commented 3 years ago

Summary

Running V3.0.0-beta.1

Trying to check and request PhotoLibrary AddOnly permission. Instead, that permission is shown as unavailable.

Notes:

  1. added NSPhotoLibraryAddUsageDescription to info.plist
  2. added pod 'Permission-PhotoLibraryAddOnly', :path => "#{permissions_path}/PhotoLibraryAddOnly" to the podfile
  3. Permission-PhotoLibraryAddOnly shows up in Pods=>Development Pods.
  4. Permission-PhotoLibrary works fine

Environment info

react-native info output:

System: OS: macOS 11.0.1 CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz Memory: 519.23 MB / 32.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 14.9.0 - /usr/local/bin/node Yarn: 1.22.5 - /usr/local/bin/yarn npm: 6.14.8 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.0 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.2, DriverKit 20.0, macOS 11.0, tvOS 14.2, watchOS 7.1 Android SDK: Not Found IDEs: Android Studio: 3.2 AI-181.5540.7.32.5056338 Xcode: 12.2/12B45b - /usr/bin/xcodebuild Languages: Java: 9.0.4 - /usr/bin/javac Python: 2.7.16 - /usr/bin/python npmPackages: @react-native-community/cli: ^4.12.0 => 4.13.0 react: 16.13.1 => 16.13.1 react-native: 0.63.2 => 0.63.2 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

I am testing on an iPhoneX with IOS 14.1.

Library version: 3.0.0-beta.1

Steps to reproduce

check(PERMISSIONS.IOS.PHOTO_LIBRARY_ADD_ONLY) .then((result) => { Alert(result); }

Describe what you expected to happen:

result === RESULTS.DENIED // at least the first time

Instead, result === RESULTS.UNAVAILABLE

zoontek commented 3 years ago

Hi 👋 There's two options:

1) Parental control is enabled on your device, PHAuthorizationStatusRestricted is therefore returned (= unavailable) 2) The permission handler is not correctly installed (see this line)

Did you installed it at the same time as Photo-Library? Or later?

Xcode really struggle with Cocoapods and caching. Did you tried closing it, deleting your DerivedData, rebuild again? (follow this)

chip-astg commented 3 years ago
  1. Parental control is enabled on your device, PHAuthorizationStatusRestricted is therefore returned (= unavailable)

I assume since PERMISSIONS.IOS.PHOTO_LIBRARY works, this is not the case.

  1. The permission handler is not correctly installed (see this line)

Wouldn't that also affect PERMISSIONS.IOS.PHOTO_LIBRARY?

Did you installed it at the same time as Photo-Library? Or later?

Just tried again:

  1. Deleted Derived data
  2. Deleted Pods
  3. Deleted podfile.lock
  4. Deleted node_modules
  5. Cleaned build folder (in Xcode)

Check shows PERMISSIONS.IOS.PHOTO_LIBRARY_ADD_ONLY as UNAVAILABLE (PERMISSIONS.IOS.PHOTO_LIBRARY shows as DENIED, as expected)

Note that I made sure NOT to set PERMISSIONS.IOS.PHOTO_LIBRARY, in case the two permissions are mutually-exclusive.

zoontek commented 3 years ago

This has nothing to do with PERMISSIONS.IOS.PHOTO_LIBRARY. But if you installed one then the other, the cache might be in a state where the first one header is present and not the second one. If you install them both at once, this case become impossible.

Which Xcode version are you using? Do you run your app though Xcode or with react-native run-ios?

chip-astg commented 3 years ago

This has nothing to do with PERMISSIONS.IOS.PHOTO_LIBRARY. But if you installed one then the other, the cache might be in a state where the first one header is present and not the second one. If you install them both at once, this case become impossible.

I was running with PERMISSIONS.IOS.PHOTO_LIBRARY first, without PERMISSIONS.IOS.PHOTO_LIBRARY_ADD_ONLY. I then added the code for PERMISSIONS.IOS.PHOTO_LIBRARY_ADD_ONLY to info.plist and Podfile and rebuilt everything, if that is what you are asking. Did I miss a step?

Which Xcode version are you using? Do you run your app though Xcode or with react-native run-ios?

Xcode 12.2 and am running the app through Xcode.

chip-astg commented 3 years ago

I just tried running in the Simulator with multiple devices, same result (so it is not some issue with iPhone X I have been using)

chip-astg commented 3 years ago

I am running RN 63.2. I'll upgraded to 63.3 and see if that fixes it.

chip-astg commented 3 years ago

I thought I might have found the cause, Permission-PhotoLibraryAddOnly was not in project.pbxproj. However, adding it and upgrading to RN63.3 did not solve the issue.

zoontek commented 3 years ago

I installed it on a clean project, could do a check and a request with only a small, unrelated hiccup: The usage description key is no correct (used for the alert in dev): https://github.com/zoontek/react-native-permissions/blob/3.0.0/ios/PhotoLibraryAddOnly/RNPermissionHandlerPhotoLibraryAddOnly.m#L8

I will fix that.

Did you tried the example project?

chip-astg commented 3 years ago

Did you tried the example project?

It works in a sample project.

So the problem was definitely adding the PHOTO_LIBRARY_ADD_ONLY after the other permissions had already been installed. Is there a trick to getting that to work? I tried uninstalling react-native-permissions completely and reinstalling, but that didn't work.

Note that this is the first component I've worked with where you have multiple Pods that can be installed at different times.

chip-astg commented 3 years ago

So the problem was definitely adding the PHOTO_LIBRARY_ADD_ONLY after the other permissions had already been installed.

Just duplicated this in my sample project. I added PERMISSIONS.IOS.CONTACTS to the Podfile and to info.plist. CONTACTS shows up as unavailable.

Screen Shot 2020-11-18 at 15 58 22

chip-astg commented 3 years ago

Running npx react-native-clean-project (which I saw in an issue solved a similar problem) fixed it in my sample project. Hopefully, it will work in my actual project.

chip-astg commented 3 years ago

Running npx react-native-clean-project (which I saw in an issue solved a similar problem) fixed it in my sample project. Hopefully, it will work in my actual project.

Worked for my main project, tool.

mtnt commented 1 year ago

I faced this issue at RN 0.69 and react-native-permissions v3.6.1

the https://github.com/zoontek/react-native-permissions/issues/540#issuecomment-729995395 worked for me, @zoontek mb you should add this solution into troubleshooting section of readme