When fetching images using the Photo framework, I am getting all images of the gallery from the PHAsset object. My question is if the images from PHAsset are globally unique or are they device specific. Can I use the same PHAsset image on different iPhones? i don't want to convert the UIImage to NSData and convert it again from NSData to UIImage.
PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
//set up fetch options, mediaType is image.
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
options.predicate = [NSPredicate predicateWithFormat:@"mediaType = %d",PHAssetMediaTypeImage];
for (NSInteger i =0; i < smartAlbums.count; i++) {
PHAssetCollection *assetCollection = smartAlbums[i];
PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:options];
NSLog(@"sub album title is %@, count is %ld", assetCollection.localizedTitle, (unsigned long)assetsFetchResult.count);
if (assetsFetchResult.count > 0 && ![assetCollection.localizedTitle isEqualToString: @"Recently Deleted"]) {
for (PHAsset *asset in assetsFetchResult) {
PHImageRequestOptions *option = [PHImageRequestOptions new];
option.synchronous = YES;
[[PHImageManager defaultManager] requestImageForAsset:asset targetSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height-100) contentMode:PHImageContentModeAspectFit options:option resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
[mutArrAsset addObject:asset];
[self.imagesURLArray addObject:result];
}];
NSLog(@"asset are %@", asset);
}}}
A PHAsset
represent a pointer to an image in the user's photo library. People have different images on their phone so it doesn't make sense to pass that pointer to a different phone. PHAsset
's id is explicted called localIdentifier
for this reason.
If you want to transfer an image from one device to a different device you have to transfer it as NSData
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.