1
votes

Hey folks I’m having trouble wrapping my head around the correct way to handle camera and photo permissions in iOS 14 and what the appropriate flow is. It feels like I’ve overlooked something simple though not sure what exactly.

For context, the user is not prompted with a request for camera or photos permission until they’ve tapped the respective button for the first time. The app includes a custom photo picker that displays available photos to select based on previous photo associations (i.e. a photo can only belong to one product at a time and wouldn’t show as “available” in the custom picker unless it wasn’t associated with a product).

If the user taps the camera button, accepts the permission request, takes a photo and taps “Use Photo”, the UIImagePickerController is dismissed and an alert is presented that asks the user to Select Photos..., Allow Access to All Photos, or Don't Allow. If the user chooses to allow access to all photos there is no problem, the photo is saved using PhotoKit APIs and the UI updated to showcase the thumbnail of the photo just taken. Everything works as expected.

If the user chooses to select certain photos, a PHPickerViewController is presented and does not include the photo just taken with the camera since it has yet to be saved. This makes sense though leaves me to wonder how do I save the image and allow the user who chooses limited photo access to select that newly taken photo? Perhaps this isn’t possible.

There are additional hiccups I’m seeing with the flow such that if the user then taps “Done” to dismiss the PHPickerViewController without making any selections after electing limited access, the app is able to save the image taken from the camera using PhotoKit APIs and the UI updated to showcase the thumbnail (this seems incorrect though I may be misunderstanding something simple).

In the same run of the app, if the user taps the photos button, they are presented with the custom picker and logging shows a fetch count of 0 photos available to the user. This makes sense since there were no selections made. However, on the next app run, if the user taps the photo button, they are presented with the alert to Select More Photos... or Keep Current Selection. If they elect to add to the photo selection, they are presented with a PHPickerViewController that shows the photo previously taken with the camera as a user selection and a fetch count of 1 for available photos. Additionally, with limited access mode, attempts to generate thumbnails have produced errors in the Xcode console indicating that an operation is not permitted or a failure to decode an asset. I've seen the following in the console: [Thumbnails] Could not open PLPositionalImageTable...

It feels like I’m missing something basic in this process of taking, saving, and using photos (even a limited selection of them) for iOS 14. Does anyone have experience with this or a resource beyond recent WWDC videos that may shed light on what I’m missing? Appreciate the help in advance.

Also fwiw I would love to rely on PHPickerViewController rather than the custom picker however unless I’m missing something, PHPickerViewController doesn’t allow us to provide a subset of photos to display and only that subset even if the subset is limited by the user selection in limited access mode. If I’m misguided I’d appreciate direction there as well. Thanks all!

2

2 Answers

1
votes

The issue is not clear how you are using a custom image picker. and how you are capturing the image. If you capturing the image using a native image picker as it looks like. Picker delegate will give image without saving in photos. But it looks like you are trying to save the image first in photos and trying to access it from there. alternatively, You can use the image once you consume the provided image.

Photos permissions are prompted when the user is trying to access photos the first time. and photo selection is asked when the user trying to access the photo the first time after the app launch.

If you have case when user is selected "Limited selection" access. You can check for current photos library selection and alert user based on selection.

switch PHPhotoLibrary.authorizationStatus() {
        case .notDetermined:
            PHPhotoLibrary.requestAuthorization { [weak self] status in
                switch status {
                case .authorized:
                    self?.initPhotoLibrary()
                case .limited:
                    // Alert user to select all photos
                default:
                    self?.handleDeniedAlbumsAuthorization()
                }
            }
            
        case .authorized:
            self.initPhotoLibrary()
        case .limited:
            // Alert user to select all photos
        case .restricted: fallthrough
        case .denied:
            handleDeniedAlbumsAuthorization()
        }

There are additional hiccups

This is based on custom image picker logic, this should not be the case for native image picker.

Check apple documentation for PHPicker: https://developer.apple.com/documentation/photokit/delivering_a_great_privacy_experience_in_your_photos_app

-1
votes
if AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) ==  AVAuthorizationStatus.authorized {
   // if de user accept before
}
else
{
   AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (response :Bool) -> Void in
      if response == true {
         // User accept the permission
      }
      else {
         // User declined the permission
      }
   });
}