0
私のiPhoneにすべてのアルバムタイトルのリストを表示しようとしています。タイトルを押すと、その特定のアルバムのすべての写真を収集view.Iは「PhotosUI」フレームワークを使用していると私は、アルバムのタイトルを取得するには、このコードを使用します。「カメラロール」と「マイフォトストリーム」のPHAssetCollectionは空です
-(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];
}
このコードそれのタイトルで特定のアルバムのすべての写真を取得するには:
-(void)showPhotosInCollectionViewForALbumWithName:(NSString*)albumName
{
libraryAssets = [NSMutableArray array];
__block PHAssetCollection *collection;
// Find the album
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.predicate = [NSPredicate predicateWithFormat:@"title = %@", albumName];
collection = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum
subtype:PHAssetCollectionSubtypeAny
options:fetchOptions].firstObject;
PHFetchResult *collectionResult = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
[collectionResult enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {
[libraryAssets addObject:asset];
}];
[self.libraryPhotosCollectoionView reloadData];
}
「Instagram」のようなアルバム、自分の携帯電話で作成したアルバムしかし、「カメラロール」と「マイフォトストリーム」のアルバムを押すと、何も表示されません。
これがどうして起こっているのか、私のデバイスの写真をすべて取得する別の方法があれば、