ios - 无法从 iOS 中的 PHAssets 访问/var/mobile/Media/PhotoData/Sync/100SYNCD/文件夹中的媒体文件?

标签 ios iphone media phasset phimagemanager

我使用了 CTAssetsPickerController 库来访问 iOS 照片。我已通过 iTunes 将照片从我的 MAC 同步到 iPhone,并且该照片在我的手机图库中以“来 self 的 Mac”形式提供。 但是,当我从选择器中选择 Assets 时,在 Assets 信息中,我得到的文件 URL 为 file:///var/mobile/Media/PhotoData/Sync/100SYNCD/IMG_0002.JPG,并且从给定 URL 中找不到任何数据

  **PHAsset *asset = [self assetAtIndexPath:indexPath];
            if (asset.mediaType == 1) {
                if (@available(iOS 9.0, *)) {
                    NSArray *arr = [PHAssetResource assetResourcesForAsset:asset];
                    if (arr) {
                        PHAssetResource *resource = arr.firstObject;
                        if (resource) {
                            NSUInteger fileSize = [[resource valueForKey:@"fileSize"] integerValue];
                            NSLog(@"size %lu",(unsigned long)fileSize);
                            if (fileSize < self.picker.maxLimitSize) {
                                [self.picker selectAsset:asset];
                                dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                                    [[PHImageManager defaultManager] requestImageDataForAsset:asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                                        NSURL *fileURL = [info valueForKey:@"PHImageFileURLKey"];
                                        NSData *imagedata = [NSData dataWithContentsOfURL:fileURL];
                                        [self.picker addURL:fileURL atIndex:self.selectedAssetsCounts];
                                        ++self.picker.selectMediaFiles;
                                    }];
                                });
                            }else{
                                [self showAlertMessageWithTitle: CTAssetsPickerLocalizedString(@"sizelimitexceed", nil) andMessage:CTAssetsPickerLocalizedString(@"mediasizelimitmessage", nil) withIndex:indexPath];
                            }
                        }
                    }**



Please guide me . thanks in advance.

最佳答案

您不应依赖PHImageFileURLKey。它从未得到官方支持,甚至没有记录在案。 使用 PHImageManager 的方法之一作为

func requestImage(for asset: PHAsset, 
       targetSize: CGSize, 
      contentMode: PHImageContentMode, 
          options: PHImageRequestOptions?, 
    resultHandler: @escaping (UIImage?, [AnyHashable : Any]?) -> Void) -> PHImageRequestID

func requestImageDataAndOrientation(for asset: PHAsset, 
                            options: PHImageRequestOptions?, 
                      resultHandler: @escaping (Data?, String?, CGImagePropertyOrientation, [AnyHashable : Any]?) -> Void) -> PHImageRequestID

请看这里: PHImageResultIsDegradedKey/PHImageFileURLKey is not found

关于ios - 无法从 iOS 中的 PHAssets 访问/var/mobile/Media/PhotoData/Sync/100SYNCD/文件夹中的媒体文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58656544/

相关文章:

ios - 在 UiView 上设计水平线

iphone - MapView 以用户坐标为中心缩放

ios - 隐藏某些 View 时对齐不同的 View ?

html - 切换到移动 View 时如何使右对齐文本移动到新行

java - 如何编译包含多媒体的 Java 应用程序?

ios - 在 Swift iOS 应用程序中存储数据供以后使用

ios 11 UITableViewHeaderFooterView 无法在动画中正确滚动

ios - 如何重新激活两个 physicsBody 之间的联系

iphone - 如何支持从 iOS 4.3 到 iOS 7 版本的应用程序

java - PhoneGap 3.1 Android 将音频文件从 www 文件夹复制到 SD 卡