如何在iOS 4中注册UIApplicationWillTerminateNotification

时间:2010-07-30 12:51:36

标签: ios4 notifications

这是一个真正的新手:

使用IOS 4。 如何在多个对象中注册UIApplicationWillTerminateNotification

谢谢!

1 个答案:

答案 0 :(得分:3)

在iOS4中,通常不会为支持后台执行的应用程序调用applicationWillTerminate。这可能就是你遇到问题的原因。

如果您已将其禁用,则可以注册对象以侦听UIApplicationWillTerminateNotification通知,和/或覆盖应用程序委托的-applicationWillTerminate:方法并将代码放在那里:

//set up this class as an observer of UIApplicationWillTerminateNotification
//so we can intervene when the app is about to exit.
[[NSNotificationCenter defaultCenter]
                         addObserver:self
                            selector:@selector(applicationWillTerminate:)
                                name:UIApplicationWillTerminateNotification
                              object:[UIApplication sharedApplication]];