如何从我的照片流专辑中获取照片 [英] How to get photo from My Photo Stream Album

查看:165
本文介绍了如何从我的照片流专辑中获取照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to get Photo from My Photo Stream. I have only localIdentifier of PHAsset.

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

For photos other than My Photo Stream album I am using below code for retrieve PHAsset.

[PHAsset fetchAssetsWithLocalIdentifiers:@["localIdentifier"] options:nil].firstObject

localIdentifier就像' 1BFC3BA2-AC95-403A-B4FF-B26AFB631581 / L0 / 001 '

localIdentifier is like '1BFC3BA2-AC95-403A-B4FF-B26AFB631581/L0/001'

它工作正常。但在我的My Photo Stream专辑中,我的PHAsset值为零。

it's working fine. But in my My Photo Stream album I am getting nil value of PHAsset.

有没有人知道我们如何使用localAsdentifier值PHAsset从My Photo Stream获取原始照片?

Does anyone having a idea how we can get original Photo from My Photo Stream using localIdentifier value of PHAsset?

推荐答案

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

I got an answer myself. I retrieve all photostream photos and compare it with particular localIdentifier. Below is my code.

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

这篇关于如何从我的照片流专辑中获取照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆