照片框架开发全解析
1. 填充新创建的相册
若要将用户“最近添加”智能相册中的第一个资源添加到新创建的相册中,可按以下步骤操作:
1. 获取“最近添加”相册的引用。
2. 获取该相册中第一个资源的引用。
3. 获取新创建相册的引用。
以下是实现代码:
// find Recently Added smart album
let result = PHAssetCollection.fetchAssetCollections(
with: .smartAlbum, subtype: .smartAlbumRecentlyAdded, options: nil)
guard let rec = result.firstObject else { return }
// find its first asset
let result2 = PHAsset.fetchAssets(in:rec, options: nil)
guard let asset1 = result2.firstObject else { return }
// find our newly created album by its local id
let result3 = PHAssetCollection.fetchAssetCollections(
withLocalIdentifiers: [self.newAlbumId], options: nil)
guard let alb2 = result3.firstObject else { return }
// ready to perform