在我做很多徒劳无功的实验之前,有没有人知道你是否可以使用Apple Photokit对共享相册进行排序。我知道原生照片应用程序无法使用。
答案 0 :(得分:0)
据我所知,您希望根据添加资产的时间戳进行排序。试试这个:
_assets = [[NSArray alloc] init];
PHFetchOptions *options = [[PHFetchOptions alloc] init];
//Sort according to date
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
//If you want just images
options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %d", PHAssetMediaTypeImage];
//Each album is an assetCollection
PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection:self.assetsCollection options:options];
_assets = fetchResult;
答案 1 :(得分:0)
您可以按任何PHAsset键(媒体类型,持续时间等)进行排序。
_assets = [[NSArray alloc] init];
PHFetchOptions *options = [[PHFetchOptions alloc] init];
//Sort according to date
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"{PHAsset.key}" ascending:NO]];
//For example
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"mediaType" ascending:NO]];
//If you want just images
options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %d", PHAssetMediaTypeImage];
//If you want just videos
options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %d", PHAssetMediaTypeImage];
//If you want both videos and photos
// leave predicate as-is
//Each album is an assetCollection
PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection:self.assetsCollection options:options];
_assets = fetchResult;
因此,您可以对相册或PHAssetCollections执行相同的操作:
let options = PHFetchOptions()
//Sort according to date
options.sortDescriptors = [NSSortDescriptor(@"{PHAssetCollection.key}" ascending:true]
//Query collection with sort descriptor
let result:PHFetchResult = PHAssetCollection.fetchAssetCollectionsWithType(PHAssetCollectionType.Album, subtype: PHAssetCollectionSubtype.AlbumCloudShared, options: nil)