ios - 如何从ALASSET照片库中获取第一张(最新)照片?

标签 ios

通过编程从iOS照片库获取最新照片是否有技巧?

我知道我可以按日期搜索,但是我必须每隔一微秒进行一次扫描,以便进行某种比较以准确地找到它。

有没有人做过这个或任何想法?

最佳答案

我之前采取的一种方法:

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]);
}];

关于ios - 如何从ALASSET照片库中获取第一张(最新)照片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21730986/

相关文章:

ios - Firebase 手机身份验证 iOS

ios - 划分 iOS API 可用性

ios - 如何用视频设置sprite/GIF图像?

ios - React Native Undefined 不是对象(评估 'this.camera.capture' )

ios - 在 iOS 上没有任何延迟地一个接一个地播放声音

ios - 游戏 Assets 有时不出现

ios - 无法将数据追加到 NSMutableData 中,出现段错误 11

ios - Picker 尚未显示

ios - 每 10 分钟重复触发一个 Action

ios - swift : Multiple targets handling: macros not working