【发布时间】:2016-06-06 01:31:12
【问题描述】:
我正在尝试使用 smartAlbum 生成仅包含视频或仅包含照片或两者的数组。
您可以在下面看到我的代码:
PHFetchResult *collectionList = [PHCollectionList fetchMomentListsWithSubtype:PHCollectionListSubtypeMomentListCluster options:nil];
PHFetchOptions *options = nil;
if (self.xSelected) {
options = [[PHFetchOptions alloc] init];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
options.predicate = [NSPredicate predicateWithFormat:@"mediaType = %d",PHAssetMediaTypeImage];
}
if (self.ySelected) {
options = [[PHFetchOptions alloc] init];
options.predicate = [NSPredicate predicateWithFormat:@"mediaType = %d",PHAssetMediaTypeVideo];
}
[collectionList enumerateObjectsUsingBlock:^(PHCollectionList *collection, NSUInteger idx, BOOL *stop) {
PHFetchResult *momentsInCollection = [PHAssetCollection fetchMomentsInMomentList:collection options:options];
for (id moment in momentsInCollection) {
PHAssetCollection *castedMoment = (PHAssetCollection *)moment;
[_smartAlbums insertObject:castedMoment atIndex:0];
}
}];
然而,这在block 内的第一行不断中断,并给出以下错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unsupported predicate in fetch options: mediaType == 2'
我做了一些研究,发现了这个link。
我想知道这是 Apple 的错误还是我的代码有问题。
似乎它适用于提到这个answer 的人,这太奇怪了,因为它基本上是一样的。
在此先感谢,
阿尼什
编辑:
我想我在 Apple 的文档中找到了答案 here。看起来 mediaType 仅适用于 PHAsset 而不是 PHAssetCollection。所以现在我想问题是如何获得PFAssetCollection 只有视频或只有图像。
【问题讨论】:
-
你知道如何仅使用视频或图像获取
PHAssetCollection吗?
标签: ios iphone nspredicate photosframework