iOS 14 Camera and Photo Permission Flow - ios

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!

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

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
}
});
}

Related

Can app take photos in the background by itself

Is it possible to make app to take a photo and save it when certain view controller is reached? I ask because I want to capture users reactions so that they can compare their reactions later on.

Detect screenshots taken ON ANY APP within my iOS app

Is it possible to detect when the user takes a screenshot in any app while my app is in the background ? And how would I do that ?
If not, can I background check regularly for screenshots (not pictures from the camera) in the photo library ? Like every minute or hour ?
One way to get your app to detect Screenshots is:
Register with the Photo Library's PHPhotoLibraryChangeObserver
When your app receives a notification that a photo has been added,
check its PHAssetMediaSubtype
If the Subtype is PHAssetMediaSubtypePhotoScreenshot, you know a new
Screenshot has been taken.
The PHPhotoLibraryChangeObserver protocol notifies you of changes that
occur in the Photos library, regardless of whether those changes are
made by your app, by a user in the Photos app, or by another app that
uses the Photos framework.
https://developer.apple.com/reference/photos/phphotolibrarychangeobserver

Can custom keyboard access user photos?

I'm looking to make a custom keyboard for iOS that accesses a user's camera roll. Is this possible? I've done a bit of research but it doesn't seem like a custom keyboard extension can access the camera roll.
A custom keyboard extension can access the camera roll, provided the user has already given full access; all the same code that works in a normal app should work in a keyboard extension as well. Per the documentation:
If you request open access by setting this key’s value to YES, your keyboard gains the following capabilities, each with a concomitant responsibility in terms of user trust:
Access to Location Services, the Address Book database, and the Camera Roll, each requiring user permission on first access
I believe that Riffsy has a feature where you can save to and recover GIFs from the camera roll.

UIImagePickerController to take multiple pictures and save them in Document directory ony by one

I need my app to provide users to click multiple pictures. I want a layout with two separate buttons, one for clicking picture and another for saving the picture taken in the document's directory of filesystem. This screen will be presented and UIImagePickerController will be opened.
When user clicks first button, we will disable this button and show the picture obtained in an overlay. And show another button(this will be enabled now) to save this picture.
When user clicks another button, we will disable this button and save it in filesystem. After saving successfully, we will again enable the first button to take more pictures.
I have tried and implemented this app and it works perfectly at our end. But our some users report of app crashing when UIImagePickerOriginalImage key returned is nil.
This doesn't even happen to them frequently. Instead they face this crash after a long usage of app. However, we have tried of taking more 200 pictures and saving too. It didn't lead to any crash.
Please anyone suggest what might be the cause for this crash. Or any other better workaround to implement this functionality.

ALAssetsLibrary ask user for permission when saving to an album? Why?

I have a game where users can take a screen shot and it will save it to a custom album named after the game. When I try and do this, iOS asks the user if the App can have access to their location information, if they say no, then the screen shot is not saved in the custom album, but rather the default album.
Why is it asking permission to use location information? I'm just taking a screen shot. It has nothing to do with the camera. I'm just copying the opengl surface and making a UIImage out of it.
This is how I'm saving the UIImage:
- (void)writeImageToSavedPhotosAlbum:(CGImageRef)imageRef orientation:(ALAssetOrientation)orientation completionBlock:(ALAssetsLibraryWriteImageCompletionBlock)completionBlock;
Is location information being put into the screen shot? If so, can I disable that so this warning doesn't come up? My game has no need for location information and I'd hate for users to think I'm tracking them.
This seems like a crazy warning since it's completely factually wrong.
As shown in the following link,
http://developer.apple.com/library/ios/#Documentation/AssetsLibrary/Reference/ALAssetsLibrary_Class/Reference/Reference.html
This method will fail with error
ALAssetsLibraryAccessGloballyDeniedError if the user has not enabled
Location Services (in Settings > General).
However, we have found that there is not location permission request in iOS 6. Maybe iOS 6 has other privacy control on Photos. So you don't need to asking location permission. Our solution is check the [[UIDevice currentDevice]systemVersion] and only save to custom album while iOS >= 6.

Resources