I am trying to find an alternative for getting album names using the photo API in iOS 8. Using ALAssets we can use: valueForProperty:ALAssetsGroupPropertyNamehowever, with the photo API, I canβt find an alternative, There is localizedTitleunder PHAssetCollection, but this is not true, it just gives me city names. I'm looking for something that can return actual group names, including those synced with iTunes.
I would be grateful for any help to find out how you do this in your applications. Apple encourages us to use the photo API for applications related to 8.0, so I prefer not to use both ALAssetLibrary and photos.
the 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"];
}
}
}
}
}
source
share