Hugo
Hugo

Reputation: 994

How to list Shared Photo Stream Albums with PhotoKit

I can obtain a list of Photo Albums created on the device with PHFetchResult *results = [PHCollectionList fetchTopLevelUserCollectionsWithOptions:nil];

I imagine there must be a similar way to obtain Shared Photo Streams Albums (or as I think they may be called now "iCloud Photo Sharing Albums"), but for the life of me...can't figure it out. Has anyone solved this problem?

Upvotes: 3

Views: 2429

Answers (2)

otusweb
otusweb

Reputation: 1678

For those looking for the swift syntax:

let result = PHAssetCollection.fetchAssetCollections(with: PHAssetCollectionType.album, subtype: PHAssetCollectionSubtype.albumCloudShared, options: nil)

result.enumerateObjects { (phassetcollection, index, setThisToTrueToStop) in
    print("\(index): \(phassetcollection.localizedTitle)  \(phassetcollection.localIdentifier)")
}

Upvotes: 3

Hugo
Hugo

Reputation: 994

PhotoKit's querying logic confuses the hell out me, but here is the answer below works for me (hint: you have to query a PHAssetCollection, not a PHCollectionList)

PHFetchResult *results = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumCloudShared options:nil]

Upvotes: 4

Related Questions