Skip to content
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

Support for the new auth status PHAuthorizationStatusLimited from iOS 14 #326

Merged
merged 3 commits into from Oct 10, 2021

Conversation

drash-course
Copy link
Contributor

@drash-course drash-course commented Jul 14, 2021

Hi! Here is a PR for a change we are currently using in our App (http://fleetback.com).

Summary

In version 4.0.4 of the lib, when you call CameraRoll.getPhotos(...) on iOS there is no distinction if you have access to all photos (PHAuthorizationStatusAuthorized) or just the one the user has given permission for (PHAuthorizationStatusLimited) because it uses the deprecated method [PHPhotoLibrary authorizationStatus];.

This change updates the lib to use [PHPhotoLibrary authorizationStatusForAccessLevel:]; and [PHPhotoLibrary requestAuthorizationForAccessLevel: handler:] if available. I put the level at PHAccessLevelReadWrite to be backwards compatible.

This PR adds a new field limited in the result of CameraRoll.getPhotos(...) that will be true if the status is PHAuthorizationStatusLimited. This lets you show in your UI that there are more photos available.

Motivation

With iOS 14, if the user chose the "Select photos..." option the first time the gallery is accessed, every subsequent time an alert is presented to the user to let them change the selection.

This second alert interrupts the user, make them do their photo selection twice, cannot be translated, and does not call the completion handler when the user is done changing their selection (you have to wait for iOS 15 for this oversight to be fixed). Fortunately you can disable it with PHPhotoLibraryPreventAutomaticLimitedAccessAlert in your Info.plist.

If you don't use UIImagePickerController it's generally better to have some non-intrusive UI in your app to change the permissions. With this PR you can now do that.

Test Plan

What's required for testing (prerequisites)?

  • A simulator or test device running iOS 14
  • An app (A) that calls CameraRoll.getPhotos(...) and displays the results
  • An app (B) that calls CameraRoll.getPhotos(...) and displays the results, with <key>PHAuthorizationStatusLimited</key><true/> in Info.plist

What are the steps to reproduce (after prerequisites)?

Test 1

  1. Install the test app A
  2. Go to the screen that uses CameraRoll.getPhotos
  3. Get prompted by the OS with an alert, choose "Select photos..."
  4. Select some photos and tap OK
  5. The promise is fulfilled with the selected results, "limited": true is returned
  6. Kill the app
  7. Relaunch and go to the screen that uses CameraRoll.getPhotos
  8. Get prompted by the OS with an alert, choose "Select more photos"

The promise is fulfilled immediately with the old selection (this is an iOS issue)

  1. The promise is fulfilled with the old results, "limited": true is returned
  2. Change your selection, tap OK
  3. The app displays the old selection

Test 2

  1. Install the test app B
  2. Go to the screen that uses CameraRoll.getPhotos
  3. Get prompted by the OS with an alert, choose "Select photos..."
  4. Select some photos, tap OK
  5. The promise is fulfilled with the selected results, "limited": true is returned
  6. Kill the app
  7. Relaunch and go to the screen that uses CameraRoll.getPhotos
  8. The promise is fulfilled with the previous selection, "limited": true is returned
  9. The app displays the selection

Test 3

  1. Install the test app A or B
  2. Go to the screen that uses CameraRoll.getPhotos
  3. Get prompted by the OS with an alert, choose "Allow access to all photos"
  4. The promise is fulfilled with all results, "limited": false is returned
  5. Kill the app
  6. Relaunch and go to the screen that uses CameraRoll.getPhotos
  7. The promise is fulfilled with all results "limited": false is returned
  8. The app displays all the results

Compatibility

The change is backwards compatible with v4.0.4.

OS Implemented
iOS
Android no changes

Checklist

  • I have tested this on a device and a simulator
  • I added the documentation in README.md
  • I updated the typed files (TS and Flow)
  • I added a sample use of the API in the example project (example/App.js)

@PanamaDonne
Copy link

Please review so it can be merged & released ASAP.

@PanamaDonne PanamaDonne mentioned this pull request Sep 22, 2021
Copy link

@doranteseduardo doranteseduardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It worked as expected

@doranteseduardo doranteseduardo merged commit 3ade8c0 into react-native-cameraroll:master Oct 10, 2021
bartolkaruza pushed a commit that referenced this pull request Oct 10, 2021
# [4.1.0](v4.0.4...v4.1.0) (2021-10-10)

### Features

* **iOS14:** Support for the new auth status `PHAuthorizationStatusLimited` from iOS 14 ([#326](#326)) ([3ade8c0](3ade8c0))
@bartolkaruza
Copy link
Collaborator

🎉 This PR is included in version 4.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants