使用“预选照片视图控制器”处理应用中有限的照片访问案例
预选照片用户界面
用于处理应用中的受限照片访问案例。PreselectedPhotoViewController
概述
Supports
- iOS 14.0 or later
How to use?
IMPORTANT
Don’t forget to add to
Privacy - Photo Library Usage Description
info.plist
let vc = PreselectedPhotoViewController()
vc.delegate = self
let nav = UINavigationController(rootViewController: vc)
present(nav, animated: true, completion: nil)
- Conform to .
PreselectedPhotoViewDelegate
// ViewController.swift
class ViewController: UIViewController, PreselectedPhotoViewDelegate {
func didTapSendImageData(_ data: Data) {
// process image data
}
func didTapSendVideoURL(_ url: URL) {
// process video url
}
}
- Ready to show
PreselectedPhotoViewController
// ViewController.swift
func showLimitedPhotoLibraryPicker() {
PreselectedPhotoViewController.StringSet.viewLibrary = "{your_own_title}"
let selectablePhotoVC = PreselectedPhotoViewController()
selectablePhotoVC.delegate = self
let nav = UINavigationController(rootViewController: selectablePhotoVC)
self.present(nav, animated: true, completion: nil)
}
- Connect method to your button action
showLimitedPhotoLibraryPicker()
// ViewController.swift
@IBAction func didTapPhotoSelection() {
showLimitedPhotoLibraryPicker()
}