ios - PHAsset图像是否在所有iPhone上都具有全局唯一性?

标签 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);
        }}}

最佳答案

PHAsset表示指向用户照片库中图像的指针。人们在手机上具有不同的图像,因此将指针传递给其他手机没有任何意义。因此,PHAsset的ID称为localIdentifier

如果要将图像从一台设备传输到另一台设备,则必须将其作为NSData传输。

关于ios - PHAsset图像是否在所有iPhone上都具有全局唯一性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44923976/

相关文章:

ios - segueing 后如何向可见的导航 Controller 添加按钮?

ios - 在 Swift 上解码 JSON 时解密字符串

objective-c - iOS,openURL 打开奇怪的网页...(欢迎来到 appe.com)

iphone - iOS 5:更新无效:部分中的行数无效

iphone - 需要帮助将带有设备 token 的 URL 从我们的 iPhone 应用程序发送到我们的数据库

ios - 如何在 Xcode 中调试间歇性缓慢的 iOS iPhone 应用程序加载时间?

ios - RESTKit 对象 BOOL 属性为 true/false JSON

ios - 如何制作一个异步方法来处理来自委托(delegate)的数据?

ios - iOS 上的 UISearchController 不调用 cellForRowAtIndexPath

iphone - 如何从移动网站打开 iOS 6 map ?