Requesting photo access from preview on iOS - ios

When opening images using presentPreviewAnimated: share menu contains "Save Image" option. It works fine if user gave access to photos before (and if user explicitly disabled access there's no such option at all), but otherwise app crashes. I can check permission before opening file, but it would be wrong if the user doesn't need to save it.
How can I check if user wants to save image and permission request is needed?

Solved by adding NSPhotoLibraryAddUsageDescription to plist, thanks to this post.

Related

Detect add photos only permission

In ios 11 we now have "Add photos only" permission setting.
But how we now determinate which photo library access level is set?
[PHPhotoLibrary authorizationStatus] works only for "Read and Write" permission check. If app asked only for "Add photos only" permission then it stays PHAuthorizationStatusNotDetermined. If user changed it from "Read and Write" to "Add photos only" it gives PHAuthorizationStatusDenied.
So, how can I tell if my app have permissions to do "Export to Camera Roll" feature, which dosen't require read permissions?
since iOS 11, in order to gain only Write access you'll need to add the NSPhotoLibraryAddUsageDescription in your info.plist.
The problem here arises if you want to check if the user allows you to do that. It cannot be done through the [PHPhotoLibrary authorizationStatus] method, since that calls out the read/write popup (and you'll need to have NSPhotoLibraryUsageDescription in your info.plist too).
If you want to check if the user gave your app access to write, you'll have to call UIImageWriteToSavedPhotosAlbum (which I'm guessing you already call if you want to add data to the gallery), and that gives you a callback which tells you if the saving worked or not, but the bigger thing is that it shows the user your NSPhotoLibraryAddUsageDescription text.
Now, in order to make sure you have access on both, you should add both NSPhotoLibraryAddUsageDescription and NSPhotoLibraryUsageDescription added to your info.plist and do your regular check with the PHPhotoLibrary, and if that fails, then you can only check when you want to save the data to the library with UIImageWriteToSavedPhotosAlbum.
I'd say you can check only with UIImageWriteToSavedPhotosAlbum but you need to actually save an image to the user gallery to do that and it's hacky, which is a no no.
Since iOS 14 you are able to check if the user gave permission for add photos only:
PHPhotoLibrary.authorizationStatus(for: .addOnly)
Unfortunately that means below iOS 14 you don't know if the user has selected the add photos only or another option. The only other way to check is to actually use UIImageWriteToSavedPhotosAlbum like mikebld said in his answer.

"Access your photos" permission dialog showing up in wrong view

I am trying to change user's profile picture in IOS, in that the user can select a picture from gallery. But when I access the gallery using UIPickerController it asks for permission to access photos; but the permission alertview pops up on a different view in the app.
How can I always allow access to photos in my app or solve this pop up issue?
There is no way to programmatically force access to photos. Privacy issue!
if you want to access a users photos you HAVE TO ask him. there is no way around it. of course this has to happen only once. as soon as the user allows / denies the access the only way to change this setting afterwards is for him to go to the settings app and change the permission there.

iOS: Control access to camera roll new appear

in my app I use ALAssetsLibrary to load access at photos in camera roll;
The first time I start my app I see the classic message, if I want give the permission to access at the photo library or not.
But I want to test this situation in each case (allow and not allowed) but I'm not able show again this message; I tried to delete app, change number version, change bundle identifier, but nothing!
Every time I run my app it not show me this message and I have ever the permission to access in the library image; I want to test what happen if I select NO.
(I know that I can change this option in general settings, but in this case I control all in viewdidappear)
I want to know what happen If I select no with that message, then is it possible show again that alert?
thanks
Ok I think I got your question. In your simulator just goto Settings-->Privacy-->Photos-->You app.
Just off that switch each time and you will get prompted with that message..!
Once a user has allowed or disallowed you app access the message will never be shown again and iOS save this permission not to bother the user again.
For the iOS simulator you can rest the settings to get the message again.

iOS: Testing device to allow access to photo library...reset setting

I was testing my app, part of which allows the user to take a photo and save it. When the alert appeared on the screen asking me to give my app access to the photo library I accidentally hit "No" (Stupid touch feature : D ). Now each time I run the app I cannot save images. Is there a way to reset that?
Just turn access on in the settings. Settings->Privacy->Photos->Your App.

iOS 6 - Can't gain access to photos?

http://developer.apple.com/library/ios/#releasenotes/General/WhatsNewIniPhoneOS/Articles/iOS6.html
In there it says "For the photo library, the existing interface supports the app being denied access." Does it mean that there is no way for the app to ask the user permission to access his photos? He'll need to manualy go to settings -> privacy -> Photos and toggle my app?
If you are using ALAssets to get access to photo library, for the first time system will ask user if he want's to share photos to your app. If user taps "Allow" - everything will be ok, otherwise, user should go to the preferences and allow it manually when he wants.
Hope it helped
No, that not true. iOS will ask user for persmission when he first time accesses his photos from your app.

Resources