
[英]How can i display only limited photos with PHPickerViewController?
[英]swift5 how to only display limited photo library after user has granted limited access to select some photos
在 WWDC2020 中,引入了新的 PHPickerViewController 和新的 PHPhotoLibrary.authorizationStatus(limited)。 但我得到了以下问题:
当用户点击按钮以显示苹果的多个图像选择器并将 requestAuthorization 显示为代码时:
let requiredAccessLevel: PHAccessLevel = .readWrite PHPhotoLibrary.requestAuthorization(for: requiredAccessLevel) { (authorizationStatus) in switch authorizationStatus { case .authorized: DispatchQueue.main.async { self.presentImagePicker() } case .limited: DispatchQueue.main.async { self.presentImagePicker() } default: break } }
self.presentImagePicker() 函数:
func presentImagePicker() { var configuration = PHPickerConfiguration(photoLibrary: .shared()) configuration.filter = .images configuration.selectionLimit = self.imageCountMax - self.images.count let picker = PHPickerViewController(configuration: configuration) picker.delegate = self let accessLevel: PHAccessLevel = .readWrite let authorizationStatus = PHPhotoLibrary.authorizationStatus(for: accessLevel) switch authorizationStatus { case .authorized: DispatchQueue.main.async { self.present(picker, animated: true) } case .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) } default: break }
}
我的问题:请看代码2,case .limited: DispatchQueue.main.async { },我想我应该把有限的照片库放在这个块中,但我不知道如何只向用户显示有限的照片库。
你可以使用这个PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: self)
方法到.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)
}
之后你必须使用委托方法来获取更新的图像。
func photoLibraryDidChange(_ changeInstance: PHChange) {
let fetchOptions = PHFetchOptions()
self.allPhotos = PHAsset.fetchAssets(with: .image, options: fetchOptions)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.