Last active
January 24, 2023 06:46
-
-
Save yimajo/6485258aa315b21bcd3d2a6eefb6928b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import PhotosUI | |
class ViewController: UIViewController { | |
@IBAction func presentPickerForImagesIncludingLivePhotos(_ sender: Any) { | |
presentPicker(filter: PHPickerFilter.images) | |
} | |
private func presentPicker(filter: PHPickerFilter) { | |
let photoLibrary = PHPhotoLibrary.shared() // PHAssetを取得するため | |
var configuration = PHPickerConfiguration(photoLibrary: photoLibrary) | |
configuration.filter = filter | |
configuration.selectionLimit = 0 | |
let picker = PHPickerViewController(configuration: configuration) | |
picker.delegate = self | |
present(picker, animated: true) | |
} | |
} | |
extension ViewController: PHPickerViewControllerDelegate { | |
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { | |
dismiss(animated: true) | |
let identifiers = results.compactMap(\.assetIdentifier) | |
let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: identifiers, options: nil) | |
fetchResult.enumerateObjects { asset, index, pointer in | |
print("アセット", asset) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PHAssetの情報を取り出したいならinfo.plistに追記必要