使用获取资产集合排除 iCloud 共享相册
Exclude iCloud shared albums with fetching asset collections
我正在尝试获取用户照片库中所有相册的列表,不包括任何 iCloud 共享相册。这是我目前使用的代码:
PHFetchOptions *userAlbumsOptions = [PHFetchOptions new];
userAlbumsOptions.predicate = [NSPredicate predicateWithFormat:@"estimatedAssetCount > 0"];
userAlbumsOptions.includeAssetSourceTypes = PHAssetSourceTypeUserLibrary;
PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary options:userAlbumsOptions];
for (PHAssetCollection *album in userAlbums) {
[self.albums addObject:album];
}
如果我没理解错的话,userAlbumsOptions.includeAssetSourceTypes
属性 应该过滤掉 iCloud 共享相册;但是,它们仍然显示在列表中。谁能建议我可能做错了什么?
一个可能的解决方案:
PHFetchOptions *userAlbumsOptions = [PHFetchOptions new];
userAlbumsOptions.predicate = [NSPredicate predicateWithFormat:@"estimatedAssetCount > 0"];
PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:userAlbumsOptions];
for (PHAssetCollection *album in userAlbums) {
if (album.assetCollectionSubtype != PHAssetCollectionSubtypeAlbumCloudShared) {
[self.albums addObject:album];
}
}
基本上,检索所有资产集合,但仅当子类型不是 PHAssetCollectionSubtypeAlbumCloudShared
时才将它们添加到相册数组中。这行得通,但我对此并不满意。 PHAssetCollectionSubtypeAlbumCloudShared
检查应该没有必要。
我正在尝试获取用户照片库中所有相册的列表,不包括任何 iCloud 共享相册。这是我目前使用的代码:
PHFetchOptions *userAlbumsOptions = [PHFetchOptions new];
userAlbumsOptions.predicate = [NSPredicate predicateWithFormat:@"estimatedAssetCount > 0"];
userAlbumsOptions.includeAssetSourceTypes = PHAssetSourceTypeUserLibrary;
PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary options:userAlbumsOptions];
for (PHAssetCollection *album in userAlbums) {
[self.albums addObject:album];
}
如果我没理解错的话,userAlbumsOptions.includeAssetSourceTypes
属性 应该过滤掉 iCloud 共享相册;但是,它们仍然显示在列表中。谁能建议我可能做错了什么?
一个可能的解决方案:
PHFetchOptions *userAlbumsOptions = [PHFetchOptions new];
userAlbumsOptions.predicate = [NSPredicate predicateWithFormat:@"estimatedAssetCount > 0"];
PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:userAlbumsOptions];
for (PHAssetCollection *album in userAlbums) {
if (album.assetCollectionSubtype != PHAssetCollectionSubtypeAlbumCloudShared) {
[self.albums addObject:album];
}
}
基本上,检索所有资产集合,但仅当子类型不是 PHAssetCollectionSubtypeAlbumCloudShared
时才将它们添加到相册数组中。这行得通,但我对此并不满意。 PHAssetCollectionSubtypeAlbumCloudShared
检查应该没有必要。