How to Display Only Limited Photos with PHPickerviewcontroller

How can i display only limited photos with PHPickerViewController?

I think it is separate API

  1. Requesting for photo access permission
  2. Displaying UIImagePicker/PHPicker view controller

ad. 1 you request access so then you can get all photos or selected photos and display them on you ui just like Instagram app do it. Then you can add Manage button to change limited access permission.

ad. 2 If you are using UIImagePicker or PHPicker you do not need to request for permission, and moreover this two view controllers give you read-only access to all photos.

So I think if you are using UIImagePicker, PHPicker you do not need to request Photo access permission.If you request it you are using it for more advanced usage and do not use UIImagePicker or PHPicker just create your custom UI....?

swift5 how to only display limited photo library after user has granted limited access to select some photos

You can use this PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: self) method into .limited

DispatchQueue.main.async {
// Here I don't know how to display only limited photo library to users (after user has selected some photos through the limited access)
PHPhotoLibrary.shared().register(self)
PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: self)
}

and after that you have to use the delegate method for get the updated images.

func photoLibraryDidChange(_ changeInstance: PHChange) {
let fetchOptions = PHFetchOptions()
self.allPhotos = PHAsset.fetchAssets(with: .image, options: fetchOptions)
}

Is request permission require for using PHPickerViewController & UIImagePickerController?

First you need to know is, according to Apple's docs

The PHPickerViewController class is an alternative to UIImagePickerController. PHPickerViewController improves stability and reliability, and includes several benefits to developers and users

So both PHPickerViewController and UIImagePickerController are just the same with new upgrade.

As default, it runs in a separate process and on read-only access you don't need any special permissions for that.

And of course if you need some advance features, like retrieving assets and collections, or updating the library from your apps you must have permission for it.

You can read more from this link for permission to access some feature if need.

iOS 14: PHPickerViewController is there any way to load all assets at the same time PHPickerResult

I got it working using single DispatchGroup. This is my delegate method implementation:

func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
picker.dismiss(animated: true) // dismiss a picker

let imageItems = results
.map { $0.itemProvider }
.filter { $0.canLoadObject(ofClass: UIImage.self) } // filter for possible UIImages

let dispatchGroup = DispatchGroup()
var images = [UIImage]()

for imageItem in imageItems {
dispatchGroup.enter() // signal IN

imageItem.loadObject(ofClass: UIImage.self) { image, _ in
if let image = image as? UIImage {
images.append(image)
}
dispatchGroup.leave() // signal OUT
}
}

// This is called at the end; after all signals are matched (IN/OUT)
dispatchGroup.notify(queue: .main) {
print(images)
// DO whatever you want with `images` array
}
}


Related Topics



Leave a reply



Submit