Ios 使用Swift 2.0将图像保存到照片库

Ios 使用Swift 2.0将图像保存到照片库,ios,swift,uiimagepickercontroller,imagelibrary,Ios,Swift,Uiimagepickercontroller,Imagelibrary,我遇到了一个上面用红色突出显示的问题。当我拍照并按“使用照片”时,它不会让我将拍摄的照片保存到iPad上的相册中。我已经研究过其他方法,但作为iOS开发的初学者,我不确定如何解决这个问题。我有时也会犯sigabrt错误 您是否提供了完成选择器 ... UIImageWriteToSavedPhotosAlbum(imageView.image!, self, "image:didFinishSavingWithError:contextInfo:", nil) ... func imag

我遇到了一个上面用红色突出显示的问题。当我拍照并按“使用照片”时,它不会让我将拍摄的照片保存到iPad上的相册中。我已经研究过其他方法,但作为iOS开发的初学者,我不确定如何解决这个问题。我有时也会犯sigabrt错误


您是否提供了完成选择器

...
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)
    }
}
。。。
UIImageWriteToSavedPhotosAlbum(imageView.image!,self,“图像:didFinishSavingWithError:contextInfo:,nil)
...
func图像(图像:UIImage,DidFinishSavingWither错误:NSError?,上下文信息:UnsafePointer){
如果错误==nil{
让ac=UIAlertController(标题:“已保存!”,消息:“您更改的图像已保存到照片中。”,首选样式:。警报)
ac.addAction(UIAlertAction(标题:“确定”,样式:。默认,处理程序:nil))
presentViewController(ac,动画:真,完成:无)
}否则{
让ac=UIAlertController(标题:“保存错误”,消息:错误?.localizedDescription,首选样式:。警报)
ac.addAction(UIAlertAction(标题:“确定”,样式:。默认,处理程序:nil))
presentViewController(ac,动画:真,完成:无)
}
}
您可以使用这个

@IBAction func downloadButton(_ sender: Any) {
    let imageRepresentation = UIImagePNGRepresentation(photoView.image!)
    let imageData = UIImage(data: imageRepresentation!)
    UIImageWriteToSavedPhotosAlbum(imageData!, nil, nil, nil)

    let alert = UIAlertController(title: "Completed", message: "Image has been saved!", preferredStyle: .alert)
    let action = UIAlertAction(title: "Ok", style: .default, handler: nil)
    alert.addAction(action)
    self.present(alert, animated: true, completion: nil)
}

您是否实现了回调方法<代码>函数图像(图像:UIImage,DidFinishSavingWitherError:NSError?,contextInfo:UnsafePointer){…}您得到的具体错误是什么?这是从你的形象中剪下来的。