繁体   English   中英

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

[英]Sorting Shared Albums with the Apple IOS Photokit

在进行大量毫无用处的实验之前,没有人知道您是否可以使用Apple Photokit对共享相册进行排序。 我知道本机照片应用程序无法运行。

据您所知,您想根据添加资产的时间戳进行排序。 尝试这个:

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

您可以按任何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;

因此,您可以对相册或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