1

我正在尝试获取用户照片库中所有相册的列表,不包括任何 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 共享相册;但是,它们仍然显示在列表中。谁能建议我可能做错了什么?

4

1 回答 1

2

一种可能的解决方案:

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检查应该是不必要的。

于 2017-07-01T19:56:26.703 回答