PHPhotoLibrary.requestAuthorization just returns .denied on macOS

I am trying to implement the ability to save a photo to the user’s photo library on macOS. When I call PHPhotoLibrary.requestAuthorization(for: .addOnly) I just get a .denied status. The user is not prompted for access.

I tried adding these entitlements: com.apple.security.personal-information.photos-library, com.apple.security.assets.pictures.read-write. I tried turning off sandboxing entirely.

I tried saving despite getting the authorization denied, but unsurprisingly that gives me this error: Domain=PHPhotosErrorDomain Code=3311

I can almost do what i want with NSSharingService(named: .addToIPhoto), but that has the side effect of launching Photos.

Is there a trick to getting PHPhotoLibrary.requestAuthorization(for: .addOnly) to work?

Thanks.

John

Have you added an NSPhotoLibraryAddUsageDescription to your app? There's some more info at these links

https://developer.apple.com/documentation/bundleresources/information_property_list/nsphotolibraryaddusagedescription https://developer.apple.com/documentation/photokit/delivering_an_enhanced_privacy_experience_in_your_photos_app

Yes, I have both NSPhotoLibraryAddUsageDescription and NSPhotoLibraryUsageDescription in my Info.plist:

<key>NSPhotoLibraryAddUsageDescription</key>
<string>photo library additions</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>photo library usage</string>

Have you, by any chance, added amfi_get_out_of_my_way=1 to your boot-args? It is known to interfere with the TCC permission system, and the OS stops displaying the permission dialogs to users. You can remove the amfi_get_out_of_my_way argument, reboot, run your app once so the OS displays the alert and you accept, and you can add the amfi_get_out_of_my_way=1 argument back.

Thank you for the response, Leo! The problem was me being silly. When I thought I had added the com.apple.security.personal-information.photos-library entitlement, I was wrong. I added it to the wrong place. 🤦‍♂️

PHPhotoLibrary.requestAuthorization just returns .denied on macOS
 
 
Q