[英]Get list of all photo albums and thumbnails for each album
如何獲取iOS中所有相冊的列表? 我知道圖像選擇器必須在某處有一個列表,因為它將它們全部顯示給用戶。 一旦我有了相冊,我將如何顯示特定相冊中所有圖像的縮略圖? 我似乎無法在文檔中找到任何內容,但我確信必須有一種方法可以做到這一點。
如果這是你要求的,你無法從UIImagePickerController
獲得那種信息。
看看AssetsLibrary框架。 甚至還有示例代碼實現了自定義圖像選擇器。
枚舉並獲取最新圖像及其縮略圖。
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// Within the group enumeration block, filter to enumerate just photos.
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
// Chooses the photo at the last index
[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
UIImage *latestPhoto = [UIImage imageWithCGImage:[representation fullScreenImage]];
UIImage *latestPhotoThumbnail = [UIImage imageWithCGImage:[alAsset thumbnail]];
// Stop the enumerations
*stop = YES; *innerStop = YES;
// Do something interesting with the AV asset.
//[self sendTweet:latestPhoto];
}
}];
} failureBlock: ^(NSError *error) {
// Typically you should handle an error more gracefully than this.
NSLog(@"No groups");
}];
從iOS 9.0開始,不推薦使用Assets Library框架。 相反,使用Photos框架,在iOS 8.0及更高版本中,它可以為用戶的照片庫提供更多功能和更好的性能。
檢查Photos框架,並檢查:PHAsset,PHAssetCollection和PHCollectionList,具體取決於您的需要。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.