0

My app only needs the 'Privacy - Photo Library Additions Usage Description' property in the plist file (app writes to Photo library, but doesn't read).

I use this code to check for permissions:

PHPhotoLibrary.requestAuthorization { status in

            if status == .authorized {
                print("Permission granted")
            } else {
                print("Unavailable")
            }

        }

In the iOS Settings for my app, even though the plist only needs 'Add Photos Only', 'Read and Write' is also listed (??), and the above code only gets the authorised status if 'Read and Write' is ticked (ticking 'Add Photos Only' just causes the above code to go through to the else statement).

I'm a bit confused to why 'Read & Write' is even listed as a setting for my app, when my plist doesn't include "Privacy - Photo Library Usage Description".

Any ideas?

Lena Verhoev
  • 231
  • 1
  • 3
  • 15

1 Answers1

4

It's because you are calling PHPhotoLibrary.requestAuthorization.

If all you need is to write blindly into the user's camera roll, do not call PHPhotoLibrary.requestAuthorization. Just go ahead and write, e.g. by calling UIImageWriteToSavedPhotosAlbum or UISaveVideoAtPathToSavedPhotosAlbum. The runtime will request authorization on your behalf.

But if you want to interact with the photo library itself, i.e. thru the Photos framework, then you need authorization and an entry under Privacy - Photo Library Usage Description, even if all you intend to do is write.


Judging by your comments, you may be confused about what requestAuthorization does. It tries to obtain permission. If all you want to know is what the current authorization status actually is, call authorizationStatus instead.

However, even then, we're talking about the photo library itself, and thus the value referred to as Read & Write in Settings.

If you want to know whether you have permission to do UIImageWriteToSavedPhotosAlbum or UISaveVideoAtPathToSavedPhotosAlbum, just go ahead and call it. If there's a permissions problem, you'll hear about it in the completion handler.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • All I need to know is if the user has granted write access to the library - are there no other calls I can use? – Lena Verhoev Apr 25 '19 at 22:19
  • If all you want to do is ask what the status _is_, call `authorizationStatus()`. But what you are asking about is Read & Write. – matt Apr 25 '19 at 22:29
  • 1
    If what you want to know is whether you have permission for UIImageWriteToSavedPhotosAlbum or UISaveVideoAtPathToSavedPhotosAlbum, just make the call and you'll be told in the completion handler if there's a permissions issue. – matt Apr 25 '19 at 22:35
  • I had been hoping to get away with this process: 1) Check if 'Privacy - Photo Library Additions Usage Description' granted. 2) If not, prompt user to access/update their settings. 3) If permission granted, create image, share it to the ActivityViewController, and when 'save to camera roll' is selected, assume that image would have been saved okay (then I'd display 'Saved' success message). Obviously, this program flow doesn't work and makes some assumptions, Will rethink it. Thanks for your help. – Lena Verhoev Apr 25 '19 at 22:58
  • 2
    Right, well, if you need to know in advance whether you are _going_ to be able to get permission, so as to decide whether to kick off a complex operation, then you need to use Privacy - Photo Library Usage Description, `authorizationStatus`, and `requestAuthorization` (and the user will see Read & Write). You cannot do the stuff you hypothesized here; for example, you cannot check in advance if Privacy - Photo Library Additions Usage Description, and you cannot prompt in advance for that kind of permission. – matt Apr 25 '19 at 23:02