以上均不适用于Swift3
。对于那些正在苦苦挣扎的人试试这个Swift3 Syntax's
Action:
@IBAction func saveToPhotos(_ sender: AnyObject) {
UIImageWriteToSavedPhotosAlbum(yourImageView.image!, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
}
Target:
func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
if error == nil {
let ac = UIAlertController(title: "Saved!", message: "Image saved to your photos.", preferredStyle: .alert)
ac.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
present(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))
present(ac, animated: true, completion: nil)
}
}
请参阅此链接以获取更多说明https://www.hackingwithswift.com/read/13/5/ saving-to-the-ios-photo-library https://www.hackingwithswift.com/read/13/5/saving-to-the-ios-photo-library