iosswiftuiimagealassetslibraryalasset

How to get ALAsset from saved photo


Is there a way to know the ALAsset corresponding to an UIImage?

I use UIImageWriteToSavedPhotosAlbum for saving a photo and I need to identify it in my asset list

UPDATE :

I used writeImageToSavedPhotosAlbum instead of UIImageWriteToSavedPhotosAlbum

alAssetLibrary.writeImageToSavedPhotosAlbum(image.CGImage, orientation: orientation) { (url, error) -> Void in
    alAssetLibrary.assetForURL(url, resultBlock: { (asset) -> Void in
        //code
    }, failureBlock: { (error) -> Void in
        //code
    })
}

Solution

  • I use UIImageWriteToSavedPhotosAlbum for saving a photo and I need to identify it in my asset list

    If you need to identify the resulting asset, why are you using UIImageWriteToSavedPhotosAlbum? It is a "stupid" function.

    If you want to save an image as an asset into the library in such a way that you have access to that asset, you need to save it a "smart" way, such ALAssetsLibrary's writeImageToSavedPhotosAlbum - which has a completion handler that hands you the URL of the resulting asset.