Well, I have found a solution to dismissing both UIActionSheets and the popover that gets created from Webviews/Textviews when detecting phone numbers/email on an iPad. The solution is basically iterating through all my views using recursion until I find the views that I want to dismiss. A lot of credit has to go to the answers I found in this post Accessing UIPopoverController for UIActionSheet on iPad.
To remove UIActionSheets:
BOOL IsActionOpen(UIView* aView) {
BOOL actionOpen = NO;
if (aView) {
if ([aView isKindOfClass:[UIActionSheet class]]) {
actionOpen = YES;
[(UIActionSheet *)aView dismissWithClickedButtonIndex:0 animated:NO];
}
else if (aView.subviews.count > 0) {
for (UIView* aSubview in aView.subviews) {
if ( IsActionOpen( aSubview)) {
if ([aView isKindOfClass:[UIActionSheet class]]) {
actionOpen = YES;
[(UIActionSheet *)aView dismissWithClickedButtonIndex:0 animated:NO];
}break;
}
}
}
}
return actionOpen;
}
- (void) removeActionSheetIfShowing {
BOOL actionOpen = NO;
for (UIWindow* w in [UIApplication sharedApplication].windows) {
actionOpen = IsActionOpen(w);
if (actionOpen)
break;
}
}
To remove the popover that is created when selecting "Add to Contacts" button from the generated UIActionSheet:
BOOL IsPopOverOpen(UIView* aView) {
BOOL popOverOpen = NO;
if (aView) {
//popover is a popoverview, not a popovercontroller. We find it by checking if UIPopoverBackgroundView exists
if([aView isKindOfClass:[UIPopoverBackgroundView class]]){
popOverOpen = YES;
[aView.superview removeFromSuperview];
}
else if (aView.subviews.count > 0) {
for (UIView* aSubview in aView.subviews) {
if ( IsPopOverOpen( aSubview)) {
if([aView isKindOfClass:[UIPopoverBackgroundView class]]){
popOverOpen = YES;
[aView.superview removeFromSuperview];
}break;
}
}
}
}
return popOverOpen;
}
- (void) removePopOverIfShowing {
BOOL popOverOpen = NO;
for (UIWindow* w in [UIApplication sharedApplication].windows) {
popOverOpen = IsPopOverOpen(w);
if (popOverOpen)
break;
}
}