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

我遇到了上面红色突出显示的问题。 当我拍照并按使用照片时,它不会让我把我拍到iPad上的照片保存起来。 我已经看了其他的方式,但我是一个初学iOS开发,我不确定如何解决这个问题。 我有时也得到一个sigabrt错误。

http://i.stack.imgur.com/Gb7o3.png

你提供了完成select器?

 ... 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) } } 

你可以用这个

 @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) } 
Interesting Posts