我能够注册 UIApplicationDidBecomeActiveNotification 并正确接收事件。但有时我会在应用程序仍在运行时收到这些通知。我怀疑内存问题会触发应用程序辞职/恢复,但无法确认是这种情况(我曾同时看到内存警告)。为什么在应用程序运行时会调用这些方法(没有调用、没有锁定等)?
我正在注册这些通知:
[[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