以编程方式从iOS Photo库中获取最新照片是否有诀窍?
我知道我可以按日期搜索,但我必须每微秒进行一次扫描,以便进行某种比较以准确找到它。
有没有人做过这个或任何想法?
答案 0 :(得分:3)
我之前采取的方法:
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
[group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
UIImage *latestPhoto = [UIImage imageWithCGImage:[representation fullScreenImage]];
*stop = YES; *innerStop = YES;
}
}];
} failureBlock: ^(NSError *error) {
NSLog(@"Error : %@", [error localisedDescription]);
}];