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.
            Asked
            
        
        
            Active
            
        
            Viewed 5,271 times
        
    4
            
            
        - 
                    Have you implemented the callback method? `func image(image: UIImage, didFinishSavingWithError error: NSError?, contextInfo:UnsafePointer
) { ... }` – TotoroTotoro Mar 03 '16 at 01:09 - 
                    What is the specific error you're getting? It's cut out of your image. – mszaro Mar 03 '16 at 01:32
 
2 Answers
8
            
            
        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)
    }
}
        Sanjan Piya
        
- 247
 - 2
 - 8
 
0
            
            
        You can use this;
@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)
}
        Celil Bozkurt
        
- 1,693
 - 16
 - 18
 
