Since I\'m using iOS 13, each of my UIAlertController shows up for about half a second and disappears instantly before any user action. Any idea ?
As I use
You can try this solution also. It is working form me.
write below method in your class.
func presentViewController(alertController: UIAlertController, completion: (() -> Void)? = nil) {
if var topController = UIApplication.shared.keyWindow?.rootViewController {
while let presentedViewController = topController.presentedViewController {
topController = presentedViewController
}
DispatchQueue.main.async {
topController.present(alertController, animated: true, completion: completion)
}
}
}
Then call it from your code as below
let alertController = UIAlertController(title: "Discard Photo?",
message: "Your photo will not be attached",
preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Keep Photo", style: .default, handler: nil))
alertController.addAction(UIAlertAction(title: "Discard", style: .default) { (_) -> Void in
self.PhotoStack.deletePhoto(at: index)
self.cameraBtn.isEnabled = true
})
self.presentViewController(alertController: alertController)