We have to upload an image into web service in a background thread. For example, I have a Home screen and Login screen. When I upload an image in home screen and navigate to the Login screen if I get a timeout error in home screen, I have to show an alert in Login screen.
NOTE : I have to call the background thread call a delegate method in the current view to display the alert instead of using UIAlertController in window root
To present alert on top of all views :
func alertWindow(title: String, message: String) {
DispatchQueue.main.async(execute: {
let alertWindow = UIWindow(frame: UIScreen.main.bounds)
alertWindow.rootViewController = UIViewController()
alertWindow.windowLevel = UIWindowLevelAlert + 1
let alert2 = UIAlertController(title: title, message: message, preferredStyle: .alert)
let defaultAction2 = UIAlertAction(title: "OK", style: .default, handler: { action in
})
alert2.addAction(defaultAction2)
alertWindow.makeKeyAndVisible()
alertWindow.rootViewController?.present(alert2, animated: true, completion: nil)
}) }
Function calling:::::
SharedClass.sharedInstance.alertWindow(title:"This your title", message:"This is your message")
The above code is working fine but i have to show the alert in the current view using delegates how to do that?