I want to dismiss my UIAlertController with a click on the 'Cancel' button when my app goes in to background.
I've set up the background notification with
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
Then in my appDidEnterBackground function I have:
- (void)appDidEnterBackground {
if (_alertController) {
UIAlertAction *cancelAction = [[_alertController actions] objectAtIndex:0];
//HERE: is there a way to trigger the cancelAction??
[_alertController dismissViewControllerAnimated:NO completion:nil];
}
}
What I'm struggling with is how to trigger the UIAlertAction programmatically. Is this possible?
UIAlertAction. You could try duplicating the code, or branching it off into a globally declared method? - MCKapurappDidEnterBackground. If you post as an answer I'll accept. - CharlesA