1

How do I check if a user was able to save to the camera roll during an activityViewController?

For example, I have an activity view controller that offers the option to save to the camera roll. After the user saves the picture, my app displays a prompt letting the user know that the image was saved. However, when the users click on the "save to camera roll" icon, he gets prompted by the OS to give permissions so my app can store photos on their camera roll. If the user rejects the permission, the activityViewController.completionWithItemsHandler still returns success, even thought the user didn't save the picture into the camera.

How can I check if the user was actually able to save the picture to the camera roll?

activityViewController.completionWithItemsHandler = { activity, success, items, error in
                if success {
                    if let activity = activity {
                        switch activity {
                        case .postToFacebook:
                            self.view.showToast(with: "Successfully posted to Facebook.")
                        case .postToTwitter:
                            self.view.showToast(with: "Successfully posted to Twitter.")
                        case .message:
                            self.view.showToast(with: "Your message has been sent.")
                        case .mail:
                            self.view.showToast(with: "Your email has been sent.")
                        case .saveToCameraRoll:
                            if PHPhotoLibrary.authorizationStatus() == .denied {
                                self.view.show(alertForDeniedPermission(to: .photoLibraryAccess), animated: true)
                            } else {
                                self.view.showToast(with: "Your picture has been saved.")
                            }
                        default:
                            self.view.showToast(with: "Success!")
                        }
                    }
                }

Checking for PHPhotoLibrary.authorizationStatus() doesn't work since the enum is always . notDetermined. I think because my app is only asking for Privacy - Photo Library Additions Usage Description and not Privacy - Photo Library Usage Description.

Marcy
  • 4,611
  • 2
  • 34
  • 52
  • you will need these 3 in the plist 1 - Privacy - Photo Library Usage Description 2 - Privacy - Photo Library Additions Usage Description 3 - Privacy - Media Library Usage Description – Shahzaib Qureshi Feb 15 '19 at 07:34
  • 1
    The code that u have written is supposed to post the image to facebook. Right ? why would it be saved to camera roll ? – Shahzaib Qureshi Feb 15 '19 at 07:39

1 Answers1

0

Since you're trying to save a photo to the photo library you will need the "Privacy - Photo Library Additions Usage Description" and Privacy - Media Library Usage Description set in your Info.plist file too.

Your app is showing not determined for the authorization status, because the user can not grant nor deny your access, because you haven't asked for it yet!

Just to give you some context, here are the different cases with explanations that the authorization status can return: (taken from the Apple developer website.)

case not determined: Explicit user permission is required for photo library access, but the user has not yet granted or denied such permission.

case restricted: Your app is not authorized to access the photo library, and the user cannot grant such permission.

case denied: The user has explicitly denied your app access to the photo library.

case authorized: The user has explicitly granted your app access to the photo library.

lajosdeme
  • 2,189
  • 1
  • 11
  • 20