我想从我的照片流中获取照片。我只有 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/