简体   繁体   中英

get file name when using writeImageToSavedPhotosAlbum

in an ios swift application, I am using writeImageToSavedPhotosAlbum to save a UIImage on the iphone

let assets : ALAssetsLibrary = ALAssetsLibrary()
let imgRef : CGImage = myImage!.CGImage
let orientation : ALAssetOrientation = ALAssetOrientation(rawValue: myImage!.imageOrientation.rawValue)!
assets.writeImageToSavedPhotosAlbum(imgRef, orientation: orientation, completionBlock: nil)

Is there a way I can get the saved image filename? or maybe to set it myself?

Thank you for any help

If you look at the spec of the method you're using you will see that the completion block you aren't using is of type ALAssetsLibraryWriteImageCompletionBlock , which has the parameters NSURL *assetURL, NSError *error .

So specify a completion block and you get the asset URL from which you can derive some information.

You can get the file path information using the completion block parameter. Instead of passing nil pass the block like:

assets.writeImageToSavedPhotosAlbum(imgRef, orientation: orientation, completionBlock:
{ (path:NSURL!, error:NSError!) -> Void in
        println("\(path)")
})

Check the ALAssetLibrary Class Reference for more information

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM