Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

saving an image to photos library using Swift 2.0

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.

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

like image 313
user5168832 Avatar asked Feb 08 '23 14:02

user5168832


1 Answers

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)
    }
}
like image 66
Sanjan Piya Avatar answered Feb 13 '23 06:02

Sanjan Piya