0

I have used the CTAssetsPickerController library to access the iOS photo. I have sync the photo from my MAC to iPhone through iTunes and the photo are available in my phone gallery as From My Mac. But when i picked the assets from picker then in assets info i am getting file URL as file:///var/mobile/Media/PhotoData/Sync/100SYNCD/IMG_0002.JPG and there is NO Data found from the given 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.

1 Answers1

0

You should not rely on PHImageFileURLKey. It was never officially supported or even documented. Use one of the methods of PHImageManager as

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

or

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

Please have a look here: PHImageResultIsDegradedKey/PHImageFileURLKey is not found

holtmann
  • 6,043
  • 32
  • 44