In some cases, you'll need to test if a UIAlertView
appeared on the screen, possibly to test if an error is shown. Unfortunately, in iOS7, the UIAlertView
does not appear in UIApplication.windows
. And in fact, the UIAlertView
is never added to any window, thus you'll need to keep a reference to it but that solution is messy.
But do not fret because there is still a way to check for existing instances of UIAlertView
on the screen.
describe "some method here" do
it "displays an alert" do
topMostAlertView = NSClassFromString('_UIAlertManager')
.performSelector(:topMostAlert)
topMostAlertView.should.not.equal nil
end
end
Note: The UIAlertManager
is an undocumented class and might cause your app to be rejected. So please use it carefully. That's also why we're only using it in our tests.
Cheers!