所有iPhone都是全球唯一的PHAsset图像吗?

时间:2017-07-05 10:41:21

标签: ios objective-c iphone phasset

使用Photo框架获取图像时,我从PHAsset对象获取图库的所有图像。我的问题是来自PHAsset的图像是全局唯一的还是特定于设备的。我可以在不同的iPhone上使用相同的PHAsset图像吗?我不想将UIImage转换为NSData并再次从NSData转换为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);
        }}}

1 个答案:

答案 0 :(得分:2)

PHAsset表示指向用户照片库中图像的指针。人们在手机上有不同的图像,因此将指针传递给不同的手机是没有意义的。出于这个原因,PHAsset的ID被称为localIdentifier

如果您想将图片从一台设备转移到另一台设备,则必须将其转移为NSData