使用Swift 2.0将图像保存到照片库 [英] saving an image to photos library using Swift 2.0
本文介绍了使用Swift 2.0将图像保存到照片库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我上面的红色突出显示了问题。当我拍照并按下使用照片时,我不会将我拍摄的照片保存到iPad上的相册中。我已经看过其他方式,但我是iOS开发的初学者,我不确定如何解决这个问题。我有时也会得到一个sigabrt错误。
I'm getting a problem highlighted in red above. When I take a picture and press use photo, it won't let me save the photo I took to the photo album on my iPad. I have looked at other ways but me being a beginner to iOS development, I'm unsure of how to fix this problem. I sometimes get a sigabrt error too.
推荐答案
您是否提供了完成选择器?
Have you provided the completion Selector?
...
UIImageWriteToSavedPhotosAlbum(imageView.image!, self, "image:didFinishSavingWithError:contextInfo:", nil)
...
func image(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer<Void>) {
if error == nil {
let ac = UIAlertController(title: "Saved!", message: "Your altered image has been saved to your photos.", preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(ac, animated: true, completion: nil)
} else {
let ac = UIAlertController(title: "Save error", message: error?.localizedDescription, preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(ac, animated: true, completion: nil)
}
}
这篇关于使用Swift 2.0将图像保存到照片库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文