How do we detect when control center on iOS 7?

2019-07-15 07:45发布

I am having an issue when the control center appears on iOS 7. Basically, the applicationDidEnterBackground is fired when the control center appears.

However in my method, I would like to detect if it's just the control center opening or the notification center since I would treat the applicationDidEnterBackground differently in that state.

Any help would be appreciated.

1条回答
做自己的国王
2楼-- · 2019-07-15 08:04

I just published a little UIWindow subclass that does exactly that. You simply subscribe to an NSNotification and can react to the user opening Control Center. Detailed instructions and setup on Github: AAWindow.

The way this is accomplished is by using a combination of NSTimer and overwriting sendEvent in UIWindow to receive all touches without blocking them. So you basically receive all touches check if they are near the lower edge of the screen, if yes set a timer for a half a second and if during this timer is running applicationWillResignActive is called you can be almost certain that ControlCenter is opened. The time has to vary if there's no statusbar, because then the app is in fullscreen and it can take the user up to 3 seconds to launch Control Center.

查看更多
登录 后发表回答