2014-11-21 96 views
1

我想通過除我自己的相冊中的照片獲取所有照片。 我嘗試使用此答案中的方法獲取所有照片。 ios - Simple example to get list of photo albums? 但我無法找到一個選項來過濾我自己的專輯。iOS 8照片框架:獲取相冊的特定列表

我使用下面的代碼...除了我自己的專輯外,我可以得到專輯,但是如何在自己的專輯中獲得除了我的照片之外的所有照片的PHFetchResult?

謝謝。

PHFetchOptions *albumsFetchOption = [[PHFetchOptions alloc]init]; 
NSString *string = @"MyCam"; 
albumsFetchOption.predicate = [NSPredicate predicateWithFormat:@"title != %@",string]; 

PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:albumsFetchOption]; 

回答

2

最後,我用的,而不是PHFetchResult NSArray中...

//獲取所有

PHFetchOptions *allPhotosfetchOption = [[PHFetchOptions alloc]init]; 
allPhotosfetchOption.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]]; 
allPhotosfetchOption.predicate = [NSPredicate predicateWithFormat:@"mediaType == 1"]; 

__block NSMutableArray *allAssetArray = [NSMutableArray new]; 
PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:allPhotosfetchOption]; 
[result enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) { 
     [allAssetArray addObject:asset]; 
}]; 

//MyCam Album 
NSString *string = @"MyCam"; 
PHFetchOptions *albumFetchOption = [[PHFetchOptions alloc]init]; 
albumFetchOption.predicate = [NSPredicate predicateWithFormat:@"title == %@",string]; 
PHFetchResult *albumResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:albumFetchOption]; 

[albumResult enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx, BOOL *stop) { 
    PHFetchResult *loftAssetResult = [PHAsset fetchAssetsInAssetCollection:collection options:nil]; 
    [loftAssetResult enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) { 
       if ([allAssetArray containsObject:asset]) { 
        [allAssetArray removeObject:asset]; 
       } 
    }]; 
}]; 
相關問題