0

Note: When I write "alert view", I'm referring to a UIAlertController UIAlertControllerStyleAlert

When my app is foregrounded after a minimum amount of time, a customPinUnlockViewController appears. This behavior occurs in iOS 8 and iOS 9 (and possibly other versions, but I haven't tested others)

If the user has enabled TouchID, then an alert view appears over the PinUnlockVC, prompting the user to use TouchID to unlock the app instead of entering the pin.

When I press the home button, the alert view is dismissed. The app is NOT backgrounded- only the alert view is dismissed. This is NOT desired behavior, but it appears that it is the default OS behavior.

Anywhere else in the app, when I press the home button, the app is backgrounded. This is desired behavior.

How do I override, what appears to be the default OS functionality in this case, the home button press in order to background the app if an alert view is visible?

I'm not sure if this occurs when any alert view is visible, or if it specific to a TouchID prompt alert view (though I don't see why it would be specific to this case).

Thanks in advance.

jungledev
  • 4,195
  • 1
  • 37
  • 52
  • Why was this down voted? – jungledev Jul 29 '16 at 18:35
  • Dunno. Not me. In terms of working on it, can you present more evidence that would help diagnose it? – danh Jul 29 '16 at 18:37
  • I have the same problem by the Push Notification Alert. By tapping the Home-Button (iPad Air 2 / iOS 11.3) the AlertView disappear and the question is declined. By the question: "If the app can use the camera", the Home-Button is useless until I answer the alert question. Did Apple changed the behaviour of the AlertViews somehow? (Got an upvote from me ;) ) – matzino May 07 '18 at 09:37

1 Answers1

1

I haven't confirmed the behavior you're seeing, but if you're right about the problem (app not going to background) and the cause (because there's a UIAlertController presented), then here's an idea for a solution: In viewDidLoad, subscribe to...

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];

Then upon receiving appWillResignActive...

- (void)appWillResignActive:(NSNotification *)notification {
    if ([self.presentedViewController isKindOfClass:[UIAlertController self]]) {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}
danh
  • 62,181
  • 10
  • 95
  • 136
  • This did not work for me, that's why I haven't accepted your submission as the correct answer. – jungledev Jul 29 '16 at 18:34
  • That's ok. Sorry that it didn't work. I think that it didn't work is an indication that your diagnosis is incorrect... that the problem isn't due to the app not backgrounding due to a UIAlertController. – danh Jul 29 '16 at 18:36
  • It absolutely is because of the UIAlertController. There's nothing else it can be. Try it out for yourself. – jungledev Jul 29 '16 at 18:41
  • So anybody can reproduce this, without your custom PinUnlock vc stacked underneath? This is what's called a minimal, complete, verifiable example. (http://stackoverflow.com/help/mcve). Can you edit your question to include that? What are the simple steps anyone can do to see the wrong behavior, and what do you believe is the correct behavior. – danh Jul 29 '16 at 18:45
  • I am working with the touchID and I have the same issue. Did you actually fix it? I think that this is only related to the system UIAlert from the TouchID, I have never seen this behaviour before. – Adriana May 17 '18 at 08:59