IOS is notified when Control Center is open like QuizUp do
How can I receive notifications when the iOS Control Center opens?
UIApplicationWillResignActiveNotification is not good enough as this notification is also sent when the Action Center is opened, a warning and other possible scenarios appear.
I was pretty sure it was not possible, but the QuizUp app is notified when the user opens the Control Center when the user is in the middle of a gameplay to prevent cheating on the game.
thank
source to share
Hi I did a lot of research on trial and error questions and came up with a solution that has proven to be very reliable. It works in all orientations and both full screen (stateless) and normal mode. AAWindow is a subclass of UIWindow and you can find it on GitHub .
The way I did it was to override it sendEvent
in UIWindow, separating TouchEvents from other events and checking if the bottom 10 percent of the screen is touching (which is the part that can open the Control Center). If there are touches and applicationWillResignActive
is called within a period of 0.5 seconds (with status bar) or 3 seconds (without status), you can be sure that this is due to the opening of the Control Center. Then the NSNotification is fired and you can react to this anywhere in the application.
source to share
I tested the approach UIPanGestureRecognizer
(with and without visible visibility) - changes if a small tab appears instead of the control center), as well as observing the notification applicationWillResignActive
and I couldn't reliably find out if the control center was open. If the pan were slow enough, the gesture recognizer would start first, but it would definitely scroll easily fast enough to bring up the control center and turn off the gesture recognition ignition altogether.
Trying to check if the app is coming from applicationWillResignActive
and then in applicationDidBecomeActive
would be a pretty reliable way to know if the app was entered and exited one of the pair states (control center, notification center, answering a phone call, etc.), but telling the difference between the message and the control center is not possible in this way.
TL; DR: I don't think there is a reliable or accurate way to know if a control center has been opened, but QuizUp might be doing something interesting to fake it, and I am open to the mistake!
source to share