How can I remove the Select Photos... option when requesting for access permission in photo library?
I use PHPhotoLibrary.requestAuthorization to create a access request and it shows me this.
I want to remove the Select Photos... option because the function of this feature is to save a image in a custom photo album.
This is my code for performing a permission request.
if PHPhotoLibrary.authorizationStatus() != PHAuthorizationStatus.authorized {
PHPhotoLibrary.requestAuthorization({ (status: PHAuthorizationStatus) in
// save depending on status
})
} else {
// save image
}
Related
In order to fetch photo's creationDate, so use requestAuthorizationForAccessLevel before show PHPickerViewController.
PHAccessLevel level = PHAccessLevelReadWrite;
[PHPhotoLibrary requestAuthorizationForAccessLevel:level handler:^(PHAuthorizationStatus status) {
if (status == PHAuthorizationStatusLimited || status == PHAuthorizationStatusAuthorized) {
dispatch_async(dispatch_get_main_queue(), ^{
PHPickerConfiguration *configuration = [[PHPickerConfiguration alloc] initWithPhotoLibrary:[PHPhotoLibrary sharedPhotoLibrary]];
configuration.filter = [PHPickerFilter imagesFilter];
configuration.selectionLimit = 1;
PHPickerViewController *picker = [[PHPickerViewController alloc] initWithConfiguration:configuration];
picker.delegate = self;
[self showViewController:picker sender:nil];
});
}
}];
although status is .limited, but iOS 14 still display all images.
How can i get only limited photos with PHPickerViewController?
So a couple of things got changed in iOS 14, let's see step by step
1. How to read PHPhotoLibrary access permission status
Old
let status = PHPhotoLibrary.authorizationStatus()
New
let status = PHPhotoLibrary.authorizationStatus(for: .readWrite)
2. How to request PHPhotoLibrary access permission
Old
PHPhotoLibrary.requestAuthorization { status in
//your code
}
New
PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in
switch status {
case .limited:
print("limited access granted")
default:
print("denied, .restricted ,.authorized")
}
}
It is your responsibility to show gallery like below sample code in case of user granted you limited permission
if status == .limited {
PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: self)
}
When you presentLimitedLibraryPicker the selected images from the previous session would be already marked check, along with a message on top of screen- "Select more photos or deselect to remove access"
In-case the user granted you limited access still you present the normal gallery using UIImagePickerController or a third party library like BSImagePicker, a gallery with all pictures would be shown even you can select and import into your app but in Xcode 12 console it will show warnings as below
Failed to decode image
[ImageManager] Failed to get sandbox extension for url: file///filepath/5003.JPG, error: Error Domain=com.apple.photos.error Code=41008 "Invalid asset uuid for client" UserInfo={NSLocalizedDescription=Invalid asset uuid for client}
After a user takes a photo in my app, there is a UIUserActivity that is presented that allows users to save and image. A pop up comes up and asks for permission to write the photo to the users photo album. However, if the user denies there is no way to prompt the user to be redirected to the photo library. PHPhoto authorization status is always returning undetermined even though permissions were already asked for. I am looking for a few things to be satisfied:
the user should be able to deny but continue to be prompted to give permission to the app if they want to save their photo.
if the user denies, I want the option of "save photo" to remain in the UIUserActivity as a potential option
How can I accomplish this?
I've tried using the PHPhotoLibrary authorization status, but it always returns undetermined. I've tried checking for .undetermined and using the PHPhotoLibrary to request access to the user's camera roll, however if the user denies at this point then the option to save photo is completely removed from the UIUserActivity pop up.
code:
activityViewController.completionWithItemsHandler = { activity, success, items, error in
if success {
if let activity = activity {
...
case .saveToCameraRoll:
handleCameraRollPermission()
func handleCameraRollPermission(status: PHAuthorizationStatus? = nil, completion: #escaping ((Bool) -> Void)) {
let authorizationStatus = status ?? PHPhotoLibrary.authorizationStatus()
switch authorizationStatus {
case .denied, .restricted:
showPermissionMissingAlert(completion: completion)
case .notDetermined:
PHPhotoLibrary.requestAuthorization { (status) in
switch(status) {
case .denied, .restricted, .notDetermined:
self.showPermissionMissingAlert(completion: completion)
default:
break
}
}
default:
completion(true)
}
}
This might be a bit overdoing it, but you could create a custom action section for the activityView. You can find more about that here and scroll down to the Adding a custom action section.
Basically you would make a custom save button that would persist regardless of permission status. When it is tapped you can check their authorization status and go from there.
I'm currently working on an app where I need to access either the photo library or the camera (or even both, it's up to the user).
If I close the app and deny the access to both camera and library for the app.
After restarting my App, it's still possible to access both, I can open and use the camera or even pick a photo from the library.
How is this possible, I thought Apple would restrict the access.
I dont think so. Apple always restrict use of camera or photo library if access is denied. Please use following code to check current status and verify it.
import Photos
if type == .CAMERA{
if AVCaptureDevice.authorizationStatus(forMediaType: AVMediaTypeVideo) == AVAuthorizationStatus.authorized {
completionHander(true) //Allowed
} else {
//Dont Know
AVCaptureDevice.requestAccess(forMediaType: AVMediaTypeVideo, completionHandler: { (granted: Bool) -> Void in
completionHander(granted)
})
}
}else{
let status = PHPhotoLibrary.authorizationStatus()
switch status {
case .authorized:
completionHander(true)//Allowed
break
case .denied, .restricted :
completionHander(false)//Not Allowed
break
case .notDetermined:
//Dont Know
PHPhotoLibrary.requestAuthorization { status in
switch status {
case .authorized:
completionHander(true)
break
case .denied, .restricted:
completionHander(false)
break
case .notDetermined:
completionHander(false)
break
}
}
}
}
Okay I know the answer...
I just didn't get the concept.
If I deny the access to the photoLibrary it is not possible to save images but, if Camera access is granted I can still use the photoLibrary.
If camera access is denied, I still get the alert with the context from the info.plist
I need to reload the music list in my app when the user allows the access to media library, and I would like to show a notification when the user disallows the access. How can I get the two callbacks?
For requesting access, I just added this line into the info.plist NSAppleMusicUsageDescription
You need to ask for the permission for accessing MPMediaLibrary, this is how you can request for it
Objective-C
[MPMediaLibrary requestAuthorization:^(MPMediaLibraryAuthorizationStatus authorizationStatus) {
if ( authorizationStatus == MPMediaLibraryAuthorizationStatusAuthorized ) {
// Reload your list here
} else {
// user did not authorize
} }];
Swift
MPMediaLibrary.requestAuthorization { (status) in
if status == .authorized {
// Reload your list here
} else {
// user did not authorize
}
}
I have an app in which I take a picture with the camera and store that image into the native gallery. But if the app doesn't have permission for that, I want the user to know that. So how do I check it?
By the way: I store the image into the gallery with:
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
You need to check the status of ALAssetLibrary
make sure you have AssetsLibrary/AssetsLibrary.h included in your file
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
// check the status for ALAuthorizationStatusAuthorized or ALAuthorizationStatusDenied e.g
if (status != ALAuthorizationStatusAuthorized) {
//show alert for asking the user to give permission
}
Swift 3
import photos
PHPhotoLibrary.requestAuthorization { status in
switch status {
case .authorized:
self.processSnapShotPhotos()
case .restricted:
print("handle restricted")
case .denied:
print("handle denied")
default:
// place for .notDetermined - in this callback status is already determined so should never get here
break
}
}
If you are using photos framework since ALAsset libraries are deprecated from ios 9 you can use PHAuthorizationStatus to check gallery access. You need to import photos framework as well.
#import <Photos/Photos.h>
- (BOOL)hasGalleryPermission
{
BOOL hasGalleryPermission = NO;
PHAuthorizationStatus authorizationStatus = [PHPhotoLibrary authorizationStatus];
if (authorizationStatus == PHAuthorizationStatusAuthorized) {
hasGalleryPermission = YES;
}
return hasGalleryPermission;
}
Note: iOS 6 Only
Is this what you are looking for
[ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized;
Other values of authorizationStatus are
ALAuthorizationStatusRestricted, // This application is not authorized to access photo data.
// The user cannot change this application’s status, possibly due to active restrictions
// such as parental controls being in place.
ALAuthorizationStatusDenied, // User has explicitly denied this application access to photos data.
ALAuthorizationStatusAuthorized // User has authorized this application to access photos data.