我试图在我的iphone中显示所有专辑标题的列表,当我按下标题时,我希望它在集合视图中显示该特定专辑的所有照片。我正在使用" PhotosUI&# 34;框架,我使用此代码获取专辑标题:
(1, datetime.date(2002, 1, 2))
(2, datetime.date(2014, 1, 15))
(3, datetime.date(2005, 10, 20))
和此代码以获取特定相册的所有照片标题:
-(void)getLibrariesList
{
NSArray *collectionsFetchResults;
albumNames = [[NSMutableArray alloc] init];
PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum
subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
PHFetchResult *syncedAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum
subtype:PHAssetCollectionSubtypeAlbumSyncedAlbum options:nil];
PHFetchResult *userCollections = [PHCollectionList fetchTopLevelUserCollectionsWithOptions:nil];
PHFetchOptions *userAlbumsOptions = [PHFetchOptions new];
userAlbumsOptions.predicate = [NSPredicate predicateWithFormat:@"estimatedAssetCount > 0"];
// Add each PHFetchResult to the array
collectionsFetchResults = @[smartAlbums, userCollections, syncedAlbums];
for (int i = 0; i < collectionsFetchResults.count; i ++) {
PHFetchResult *fetchResult = collectionsFetchResults[i];
for (int x = 0; x < fetchResult.count; x ++) {
PHCollection *collection = fetchResult[x];
albumNames[x] = collection.localizedTitle;
}
}
//update the tableview
[self.libraryTableView reloadData];
}
对于某些专辑,它的工作,专辑如&#34; Instagram&#34;和我用手机创建的专辑,但是当我按下&#34;相机胶卷&#34;和#34;我的照片流&#34;专辑它显示任何东西。
为什么会发生这种情况或是否有其他方式来获取我设备的所有照片?
答案 0 :(得分:2)
我得到了答案。我检索所有相机胶卷照片和视频。以下是我的代码。
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
collection = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum
subtype:PHAssetCollectionSubtypeSmartAlbumUserLibrary
options:fetchOptions].firstObject;
collectionResult = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
NSLog(@"Custom album images::%@",collectionResult);
[collectionResult enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop)
{
NSLog(@"Custom album::%@",asset);
NSLog(@"Collection Result Count:%lu", (unsigned long)self.collectionResult.count);
//add assets to an array for later use in the uicollectionviewcell
}];