Error when selecting photo from Library

Hello, I am able to select a photo from the Simulator's library and display the image; however, when testing on a device, the image is displayed for only about 2 lines and the rest of the image is grey. The camera works fine, just pulling from the Library


The code:

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        debugPrint(info)
        
        if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] {
            imageView.image = pickedImage as? UIImage
        }

        picker.dismiss(animated: true, completion: nil)
    }

The error:

"Select photo from Library"
[__C.UIImagePickerControllerInfoKey(_rawValue: UIImagePickerControllerMediaType): public.image, __C.UIImagePickerControllerInfoKey(_rawValue: UIImagePickerControllerImageURL): file:///private/var/mobile/Containers/Data/Application/353124C0-4BA6-41F8-AD29-D2D59D392A32/tmp/5E75F594-077A-42A4-81FF-7895E135B1D6.jpeg, __C.UIImagePickerControllerInfoKey(_rawValue: UIImagePickerControllerOriginalImage): <UIImage:0x2814082d0 anonymous {1656, 765}>, __C.UIImagePickerControllerInfoKey(_rawValue: UIImagePickerControllerReferenceURL): assets-library://asset/asset.JPG?id=A5371371-FFD0-43D4-8CEB-0A887E2DBBB5&ext=JPG]


2019-09-04 14:39:19.745759-0500 AnnotatedImageView[5782:3228117] createDataWithMappedFile:1508:  'open' failed '/var/mobile/Media/PhotoData/Mutations/DCIM/100APPLE/IMG_0050/Adjustments/FullSizeRender.jpg'    error = 1 (Operation not permitted)
2019-09-04 14:39:19.745894-0500 AnnotatedImageView[5782:3228117] createDataWithMappedFile:1508:  'open' failed '/var/mobile/Media/PhotoData/Mutations/DCIM/100APPLE/IMG_0050/Adjustments/FullSizeRender.jpg'    error = 1 (Operation not permitted)
2019-09-04 14:39:19.746004-0500 AnnotatedImageView[5782:3228117] createDataWithMappedFile:1508:  'open' failed '/var/mobile/Media/PhotoData/Mutations/DCIM/100APPLE/IMG_0050/Adjustments/FullSizeRender.jpg'    error = 1 (Operation not permitted)
2019-09-04 14:39:19.746923-0500 AnnotatedImageView[5782:3228117] createDataWithMappedFile:1508:  'open' failed '/var/mobile/Media/PhotoData/Mutations/DCIM/100APPLE/IMG_0050/Adjustments/FullSizeRender.jpg'    error = 1 (Operation not permitted)
2019-09-04 14:39:19.748324-0500 AnnotatedImageView[5782:3228117] [0x10212c800] Decoding failed with error code -1
2019-09-04 14:39:19.748359-0500 AnnotatedImageView[5782:3228117] [0x10212c800] Decoding: C0 0x067802FD 0x0068304A 0x22111100 0x000C0004 225579
2019-09-04 14:39:19.748383-0500 AnnotatedImageView[5782:3228117] [0x10212c800] Options: 1656x765 [FFFFFFFF,FFFFFFFF] 00025060

Replies

I just tested with the latest 13.1 beta 2 and it looks like all is working


"Select photo from Library"
[__C.UIImagePickerControllerInfoKey(_rawValue: UIImagePickerControllerImageURL): file:///private/var/mobile/Containers/Data/Application/BA5F1692-FE24-4F4B-B90C-14659560425D/tmp/6B3A65E7-4F3B-4DF1-B8A9-9F782A336C5F.jpeg, __C.UIImagePickerControllerInfoKey(_rawValue: UIImagePickerControllerReferenceURL): assets-library://asset/asset.JPG?id=C6819558-2648-44F8-AB15-25798016D902&ext=JPG, __C.UIImagePickerControllerInfoKey(_rawValue: UIImagePickerControllerMediaType): public.image, __C.UIImagePickerControllerInfoKey(_rawValue: UIImagePickerControllerOriginalImage): <UIImage:0x2805cc900 anonymous {2048, 1536}>]

Same exact problem, in theory UIImagePickerController doesn't need permissions on info.plist but it seems is not true.


I added this code for test before import a picture. I also add NSPhotoLibraryUsageDescription andNSPhotoLibraryAddUsageDescription :

(This force iOS to ask the user for explicit permission to camera roll, and then UIImagePickerController seems is working, probably some code is unnecesary.)


PHFetchOptions *userAlbumsOptions = [PHFetchOptions new];

userAlbumsOptions.predicate = [NSPredicate predicateWithFormat:@"estimatedAssetCount > 0"];


PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:userAlbumsOptions];


[userAlbums enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx, BOOL *stop) {

NSLog(@"album title %@", collection.localizedTitle);

PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsInAssetCollection:collection options:nil];

PHAsset *asset = [assetsFetchResult objectAtIndex:0];

asset = nil;


}];