-1

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.

Mehul Thakkar
  • 12,440
  • 10
  • 52
  • 81

1 Answers1

0

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;
}
Maulik
  • 19,348
  • 14
  • 82
  • 137
  • @MDThakkar: your app should not be in background ! – Maulik Dec 11 '13 at 09:33
  • No, my app is in foreground, I have done the task as: scheduled alarm after 1 minute, i have button, when i press button , then i had kept sleep(60), so app gone to sleep for 1 minute(during which alarm have triggered alert), and then i am checking alert by using your code, – Mehul Thakkar Dec 11 '13 at 09:35
  • you mean when app is awake again then alert is already on the screen and you fire the above method but didn't work? – Maulik Dec 11 '13 at 09:40
  • It is not giving me answer.., i dont have downvoted you, someone other has downvoted you, It is always printing UILayoutContainerView, i am upvoting you, i dont want to make you unsatisfied – Mehul Thakkar Dec 11 '13 at 10:18
  • @MDThakkar: I've tested the code. It's working here. What I've done is: First I've show `UIAlertView` and then after 1 second I fired above method, and it returns `true` with log `UIAlertView` !!! – Maulik Dec 11 '13 at 10:23