仅当“通知中心或控制中心"出现时如何检查在 applicationDidBecomeActive 中触发 [英] How to check only when "Notification Center or Control Center" are triggered in applicationDidBecomeActive
问题描述
众所周知,applicationDidBecomeActive 会在我们打开和关闭底部控制中心/顶部通知中心时调用.
As we all know, applicationDidBecomeActive will call when we open and close the Bottom Control Center / Top Noficication Center.
但是我想知道在 applicationDidBecomeActive 什么时候仅仅因为这两个事件,以便在用户打开和关闭通知中心或控制中心时处理一些功能.
But I want to know in the applicationDidBecomeActive when only because of these 2 events, to handle some functionality when user opens and close Notification Center or Control Center.
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if(/*Code for DidBecomeActive Called Because of Contol Center*/ --- )
{
}
if(/*Code for DidBecomeActive Called Because of Notification Center*/)
{
}
}
谁帮我查一下
由于通知中心而调用 DidBecomeActive 的代码
由于控制中心而调用 DidBecomeActive 的代码
推荐答案
我不确定您是否可以完全实现您想要的 - 但您可以接近.当您拉下通知中心(或上拉控制中心,或进入应用切换器)时,您将获得:
I'm not sure you can achieve exactly what you want - but you can get close. When you pull the Notification Center down (or the Control Centre up, or enter App Switcher) you will get:
applicationWillResignActive
关闭面板并返回应用程序将调用:
Closing the panel and returning to the app will call:
applicationDidBecomeActive
现在完全后台应用改为调用此序列:
Now fully backgrounding the app instead calls this sequence:
applicationWillResignActive
applicationDidEnterBackground
并重新打开应用调用:
applicationWillEnterForeground
applicationDidBecomeActive
所以你需要做的就是使用一个标志来跟踪序列:
So all you need to do is use a flag to track the sequence:
@property (nonatomic, readwrite) BOOL wasControlCenter;
- (void)applicationWillResignActive:(UIApplication *)application {
_wasControlCenter = YES;
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
_wasControlCenter = NO;
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
_wasControlCenter = NO;
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
if (_wasControlCenter) {
// Do your thing
}
}
不幸的是,我认为没有办法区分控制中心、通知中心、应用切换器等.
Unfortunately I don't think there's a way to differentiate between Control Center, Notification Center, App Switcher etc.
这篇关于仅当“通知中心或控制中心"出现时如何检查在 applicationDidBecomeActive 中触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!