RanLearns
RanLearns

Reputation: 4176

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?

Upvotes: 3

Views: 2727

Answers (1)

matt
matt

Reputation: 534893

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.

Upvotes: 2

Related Questions