Checking for Alerts Programmatically in iOS

363 views Asked by At

I have Scenario like,
I scheduled 2-3 alarms in my iPhone. Now I am running my app. When my app is executing, and if alarm has been triggered(or any other type of alert shown in my device), i want to know about that alert programmatically to App and do some task according to the alert i got. so, just i want to know that is there anyway by which you get to know that some alert has been displayed(may be system alert) on your screen.

1

There are 1 answers

5
Maulik On

You can by : (Not tested with System Alerts)

- (BOOL)isALertOnScreen
{
    for (UIWindow* window in [UIApplication sharedApplication].windows)
    {
        NSArray* subviews = window.subviews;
        if ([subviews count] > 0)
        {
            for (id obj in subviews)
            {
                DLog(@"%@",[obj class]);
                if ([obj isKindOfClass:[UIAlertView class]])
                    return YES;
            }
        }
    }
    return NO;
}