ios - 如何从我的照片流相册中获取照片

标签 ios objective-c phasset

我想从我的照片流中获取照片。我只有 PHAsset 的 localIdentifier。

对于我的照片流相册以外的照片,我使用下面的代码来检索 PHAsset。

[PHAsset fetchAssetsWithLocalIdentifiers:@[“localIdentifier”] options:nil].firstObject

localIdentifier 类似于“1BFC3BA2-AC95-403A-B4FF-B26AFB631581/L0/001

它工作正常。但是在我的“我的照片流”相册中,PHAsset 的值(value)为零。

有没有人知道我们如何使用 PHAsset 的 localIdentifier 值从我的照片流中获取原始照片?

最佳答案

我自己得到了答案。我检索所有照片流照片并将其与特定的 localIdentifier 进行比较。下面是我的代码。

PHFetchOptions *userAlbumsOptions = [PHFetchOptions new];
            userAlbumsOptions.predicate = [NSPredicate predicateWithFormat:@"estimatedAssetCount > 0"];
            PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumMyPhotoStream options:userAlbumsOptions];

            [userAlbums enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx1, BOOL *stop) {
                NSLog(@"album title %@", collection.localizedTitle);
                PHFetchOptions *fetchOptions = [PHFetchOptions new];
                fetchOptions.predicate = [NSPredicate predicateWithFormat:@"self.localIdentifier CONTAINS [cd] 'my identifier value'"];
                PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsInAssetCollection:collection options:fetchOptions];
                [assetsFetchResult enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop1) {
                    [[PHImageManager defaultManager] requestImageDataForAsset:asset options:option resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                        UIImage *imgResult = [UIImage imageWithData:imageData scale:1];
                    }];
                }];
            }]

关于ios - 如何从我的照片流相册中获取照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36003835/

相关文章:

ios - 为什么在输出到文件时需要 Brad Larson 的 GPUImage 框架中的屏幕外缓冲区

带有推送套件的 IOS voip 应用程序

iOS:在 UIScrollView 中水平自动调整组件大小

swift - 我正在尝试从本地标识符中获取 Assets 并在 collectionview 中显示图像,但它会导致滚动抖动

ios - 字符串中的 Swift 日期总是返回 nil

ios - NSPredicate: 'add' 一对多关系CoreData中所有实体的属性值

objective-c - 如何以编程方式创建分割 View ?

objective-c - 获取设置的纪元时间与现在的秒数之间的差异

ios - 优化 iPhone 存储的 PHAsset

ios - 使用本地镜像 URL 或 UIIMage 获取 PHAsset?