简体   繁体   English

使用Apple IOS Photokit对共享相册进行排序

[英]Sorting Shared Albums with the Apple IOS Photokit

Before I do a lot of fruitless experimenting, does anyone know if you can sort shared albums using the Apple Photokit. 在进行大量毫无用处的实验之前,没有人知道您是否可以使用Apple Photokit对共享相册进行排序。 I know the native photos app is not able to. 我知道本机照片应用程序无法运行。

As far i understand from your question, you want to sort based on the timestamp at which asset was added. 据您所知,您想根据添加资产的时间戳进行排序。 Try this: 尝试这个:

_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;

You can sort by any PHAsset key (mediaType, duration, etc). 您可以按任何PHAsset键(mediaType,持续时间等)进行排序。

_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;

So, you can do the same for albums or PHAssetCollections: 因此,您可以对相册或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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM