My hope is to save a screenshot successfully, but until now, my code is saving the screen twice and I do not know why.
I have the following:
class finalPostal: UIViewController{
var gesture = UILongPressGestureRecognizer()
override func viewWillAppear(animated: Bool) {
gesture = UILongPressGestureRecognizer(target: self, action: "screenShotMethod")
gesture.minimumPressDuration = 1.5
view.addGestureRecognizer(gesture)
}
func screenShotMethod() {
let layer = UIApplication.sharedApplication().keyWindow!.layer
let scale = UIScreen.mainScreen().scale
UIGraphicsBeginImageContextWithOptions(layer.frame.size, false, scale);
layer.renderInContext(UIGraphicsGetCurrentContext()!)
let screenshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil)
let alertSaved = UIAlertController(title: "Caputra guardada", message: "", preferredStyle: .ActionSheet)
alertSaved.addAction(UIAlertAction(title: "Ok", style: .Default, handler: {action in
self.view.removeGestureRecognizer(self.gesture)
}))
presentViewController(alertSaved, animated: true, completion: nil)
}