Home>

Create an image folder that can be selected multiple times in collectionView.
The screen movement is as follows
Select one image (s)
2 Press the enter button
3Selected image is displayed on another screen

I think you can edit images in the default image folder of iphone.
If i edit the image and select the edited image, the image before editing will be displayed in 3.
How can I select the edited image?

The screen display at one point shows the edited image,
Since it is the pre-edit image at the 3 time point, isn't the storage method of the value stored at the time of cell selection good? I think.

In addition, since the display of 3 does not output the retained image as it is, it is displayed from the URL of the image, so I think that the URL is not accurate.

The source when selecting a cell is as follows

// Manage images in cache
    var fetchResult: PHFetchResult<PHAsset>!

    override func collectionView (_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        // Get the ASSET for the cell
        let asset = fetchResult.object (at: indexPath.item)
        guard let cell: GridViewCell = collectionView.cellForItem (at: indexPath) as? GridViewCell else {return}
        // If the selected image is a panoramic image
        if asset.mediaSubtypes == PHAssetMediaSubtype.photoPanorama {
            let title = "Select image"
            let message = "Panorama cannot be selected"
            let okText = "OK"
            let alert = UIAlertController (title: title, message: message, preferredStyle: UIAlertController.Style.alert)
            let okeyButton = UIAlertAction (title: okText, style: UIAlertAction.Style.default, handler: {(action) in
                // cell release
                collectionView.deselectItem (at: indexPath, animated: true)
            })
            alert.addAction (okeyButton)
            self.present (alert, animated: true, completion: nil)
        } else {
        // Store URL
        asset.getURL (completionHandler: {(action) in
            self.imagePathList.append (action!)
        })
            // Store local identifier
            selectedAssetLocalIdentifiers.append (cell.representedAssetIdentifier)
            // Image storage
            imageList.append (cell.imageView.image!)
            // reload cell
            reloadSelectedCells ()
            disableUserInteractionIfNeed (collectionView)
        }
    }
extension PHAsset {
    func getURL (completionHandler: @escaping ((_ responseURL: URL?)->Void)) {
        if self.mediaType == .image {
            let options: PHContentEditingInputRequestOptions = PHContentEditingInputRequestOptions ()
            options.canHandleAdjustmentData = {(adjustmeta: PHAdjustmentData)->Bool in
                return true
            }
            self.requestContentEditingInput (with: options, completionHandler: {(contentEditingInput: PHContentEditingInput ?, info: [AnyHashable: Any])->Void in
                completionHandler (contentEditingInput! .fullSizeImageURL as URL?)
            })
        } else if self.mediaType == .video {
            let options: PHVideoRequestOptions = PHVideoRequestOptions ()
            options.version = .original
            PHImageManager.default (). RequestAVAsset (forVideo: self, options: options, resultHandler: ((asset: AVAsset ?, audioMix: AVAudioMix ?, info: [AnyHashable: Any]?)->Void in
                if let urlAsset = asset as? AVURLAsset {
                    let localVideoUrl: URL = urlAsset.url as URL
                    completionHandler (localVideoUrl)
                } else {
                    completionHandler (nil)
                }
            })
        }
    }
}
  • Answer # 1

    Self-solved.
    It was possible to cope by setting the return of getURL to false.

Related articles