Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift - checking for system alert on the screen

If I present an AlertController using self.present(alert, animated: true, completion: nil) then I can also check if that alert is onscreen using if self.presentedViewController == nil

When it is an alert controller presented by the system, self.presentedViewController is still nil even though there is an alert view on the screen.

Is there any way I can check for whether this alert is onscreen?

like image 572
RanLearns Avatar asked Dec 06 '25 03:12

RanLearns


1 Answers

Look to see whether the app’s keyWindow is your window. If it isn’t, something is being presented in front of your app by the system.

Also look at your app’s state. If it isn’t active, it has been deactivated by something appearing front of it.

like image 155
matt Avatar answered Dec 08 '25 16:12

matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!