gpt4 book ai didi

ios - 虚假的 UIApplicationDidBecomeActiveNotification 通知

转载 作者:行者123 更新时间:2023-11-29 13:15:25 34 4
gpt4 key购买 nike

我能够注册 UIApplicationDidBecomeActiveNotification 并正确接收事件。但有时我会收到这些通知 WHILE 应用程序仍在运行。我怀疑内存问题会触发应用程序退出/恢复,但无法确认是这种情况(我同时看到一次内存警告)。在应用程序运行时调用这些方法的任何原因(无调用、无锁定等)?

我正在注册这些通知:

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

(这是在使用 dispatch_once 的单例构造函数中完成一次)

对应的函数:

-(void)appDidBecomeActiveNotif:(NSNotification*)notif
{
NSLog(@"appDidBecomeActiveNotif called");
}

-(void)appWillResignActiveNotif:(NSNotification*)notif
{
NSLog(@"appWillResignActiveNotif called");
}

这是一些日志:

2013-04-11 09:28:11.401 App[1499:907] appWillResignActiveNotif
2013-04-11 09:28:13.505 App[1499:907] appDidBecomeActiveNotif

最佳答案

这是文档中关于这些通知的内容:

UIApplicationDidBecomeActiveNotification Posted when the application becomes active. An application is active when it is receiving events. An active application can be said to have focus. It gains focus after being launched, loses focus when an overlay window pops up or when the device is locked, and gains focus when the device is unlocked.

UIApplicationWillResignActiveNotification Posted when the application is no longer active and loses focus. An application is active when it is receiving events. An active application can be said to have focus. It gains focus after being launched, loses focus when an overlay window pops up or when the device is locked, and gains focus when the device is unlocked.

那么,是否有任何覆盖窗口弹出窗口或您是否锁定了设备或类似的东西?

另外,为什么不使用 AppDelegate 中的方法来监听这些事件呢?

编辑

问题似乎是 MapKit 弹出窗口要求用户使用它的位置。

关于ios - 虚假的 UIApplicationDidBecomeActiveNotification 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15943520/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com