I've been trying to find an alternative for getting the album names with the Photos API in iOS 8. With ALAssets, we can use: valueForProperty:ALAssetsGroupPropertyName
however with the Photos API, I can't seem to find an alternative. There is: localizedTitle
under PHAssetCollection
but that isn't right either, it just gives me the city names. I'm looking for something that can return the actual names of the groups, including ones synced with iTunes.
I'd appreciate any help to see how you do this in your apps. Apple is encouraging us to only use the Photos API for apps linked with 8.0, so I'd rather not use both ALAssetLibrary and Photos.
Code:
- (NSString *)nameForAlbumInCollection:(id)collection
{
NSString *title = nil;
if ([PHAsset class])
{
title = [collection localizedTitle];
}
else
{
title = [collection valueForProperty:ALAssetsGroupPropertyName];
}
return title;
}
- (void)setup
{
self.recentsCollectionDataSource = [[NSMutableOrderedSet alloc]init];
self.favoritesCollectionDataSource = [[NSMutableOrderedSet alloc]init];
self.albumsTableDataSource = [[NSMutableOrderedSet alloc]init];
NSMutableArray *segmentTitles = [[NSMutableArray alloc]init];
self.assetsFetchResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum | PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:nil];
if (!self.parentController.canTakeOrChooseVideo)
{
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"mediaType = %i",PHAssetMediaTypeImage];
}
for (PHAssetCollection *sub in self.assetsFetchResult)
{
PHFetchResult *assetsInCollection = [PHAsset fetchAssetsInAssetCollection:sub options:nil];
for (PHAsset *asset in assetsInCollection)
{
NSLog(@"%@",[self nameForAlbumInCollection:sub]);
[self.recentsCollectionDataSource addObject:asset];
if (![segmentTitles containsObject:@"Recents"])
{
[segmentTitles addObject:@"Recents"];
[segmentTitles addObject:@"Albums"];
}
if (asset.isFavorite)
{
[self.favoritesCollectionDataSource addObject:asset];
if (![segmentTitles containsObject:@"Favorites"])
{
[segmentTitles addObject:@"Favorites"];
}
}
}
}
}