Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use PHAuthorizationStatusLimited in iOS 14

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?

like image 358
Mr.Laity Avatar asked Sep 10 '20 03:09

Mr.Laity


People also ask

How do I use iOS automations on iOS 14?

Open the iOS Shortcuts App and tap on the Automation button at the bottom of the app. To get some ideas for what can be done with iOS automations, browse through the following screenshots of iOS 14 actions.

Should you give apps certain permissions in iOS 14?

You can opt to give apps only an approximate location lock. iOS 14 includes a couple of new ways that you can give apps certain permissions, but only up to a point. The idea is that there are some apps you trust a bit more than others in terms of looking at your photos or tracking where you are.

What are the privacy features of iOS 14?

The iOS 14 Privacy and Security Features You Should Know 1 Know When Apps Use Your Camera and Mic. Apps on iOS have to explicitly ask for your permission to use the camera and microphone, and from iOS 14 onwards, you'll ... 2 Limit Access to Photos and Location. ... 3 Sniff Out Bad Passwords. ... 4 Discourage Wi-Fi Tracking. ...

How do I enable unknown sources on iOS 14?

How do I enable unknown sources in iOS? Head to Settings, then tap Security and toggle the Unknown sources switch to On … How do I enable unknown sources? Go to Settings & gt; Security. Check the option “Unknown sources”. Tap OK on the prompt message. Select “Trust”. Why can’t I install apps from unknown sources?


1 Answers

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"

enter image description here

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}
like image 51
Sheshnath Avatar answered Sep 17 '22 13:09

Sheshnath