如何从所有相册(包括图像和视频)中获取资产?

let fetchOptions = PHFetchOptions()
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: true)]
let allPhotos = PHAsset.fetchAssets(with: .image, options: fetchOptions)


此代码将仅从相机胶卷中获取图像。

最佳答案

您可以使用此代码从iPhone中获取所有资产。

PHPhotoLibrary.shared().register(self as PHPhotoLibraryChangeObserver)

        if fetchResult == nil {

            let allPhotosOptions = PHFetchOptions()
            allPhotosOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
            fetchResult = PHAsset.fetchAssets(with: allPhotosOptions)
        }

08-15 20:07