How can i display only limited photos with PHPickerViewController?
I think it is separate API
- Requesting for photo access permission
- 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 toUIImagePickerController
.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
Moya/Alamofire - Url Encoded Params with Same Keys
How to Get User Data from Facebook Sdk on iOS
Transition Delegate for Uitabbarcontroller Animation
How to Change Searchbar Border Color
Restkit, Coredata and Swift - I Can't Seem to Fetch Results Back Out
How to Rotate a Scnsphere Using a Pan Gesture Recognizer
Drawing an Infinite Grid in iOS
Saving Already Created Live Photos
Nsubiquityidentitydidchangenotification and Sigkill
Blur Effect - Background Uitextfield
Set the Center of a Uibutton Programmatically - Swift
How to Detect Which Annotation Was Selected in Mapview
Swift 3 - Nsfetchrequest Distinct Results
How to Create a Ntlm Authentication Header to Use with Alamofire
Design Pattern for Realm Database Swift 3.1 - Singleton
Swift 3 - How to Improve Image Quality for Tesseract
Changing Font Size in a Label for Only iPhone 4S, Is This Possible
Avcapturesession and Avaudiosession Recording Video While Background Music Playing Only Works Once