简体   繁体   English

使用writeImageToSavedPhotosAlbum时获取文件名

[英]get file name when using writeImageToSavedPhotosAlbum

in an ios swift application, I am using writeImageToSavedPhotosAlbum to save a UIImage on the iphone 在ios swift应用程序中,我正在使用writeImageToSavedPhotosAlbum在iPhone上保存UIImage

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 . 如果查看所使用方法的规范,您会发现未使用的完成块的类型为ALAssetsLibraryWriteImageCompletionBlock ,其参数为NSURL *assetURL, NSError *error

So specify a completion block and you get the asset URL from which you can derive some information. 因此,指定一个完成块,您将获得资产URL,可以从中获取一些信息。

You can get the file path information using the completion block parameter. 您可以使用完成块参数获取文件路径信息。 Instead of passing nil pass the block like: 与其传递nil传递块:

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

Check the ALAssetLibrary Class Reference for more information 检查ALAssetLibrary类参考以获取更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用iOS的writeImageToSavedPhotosAlbum时获取实际文件名 - Get actual file name when using writeImageToSavedPhotosAlbum for iOS 使用writeImageToSavedPhotosAlbum时出现iOS错误 - iOS error when using writeImageToSavedPhotosAlbum writeImageToSavedPhotosAlbum并枚举相册中的图像 - writeImageToSavedPhotosAlbum and enumerate images in the album 使用iPad相机选择照片并获取文件名 - Pick a photo by using iPad camera and get the file name 如何使用Photos框架获取供参考URL使用的文件名? - How to get the name of file for reference url using Photos framework? 如何使用UIDocumentPickerViewController获得原始文件名? - How can i get the original file name using UIDocumentPickerViewController? 使用writeImageToSavedPhotosAlbum将UIImage保存到相册 - Save UIImage to Photo Album with writeImageToSavedPhotosAlbum iOS-信号量不等待ALAssetsLibrary writeImageToSavedPhotosAlbum方法完成 - ios - semaphore not waiting for ALAssetsLibrary writeImageToSavedPhotosAlbum method to complete 当项目名称有空格时,无法从桥接头获取正确的文件路径 - Unable to get correct file path from bridge header when project name has a space 有没有办法获取UIImage文件名? - Is there a way to get UIImage file name?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM