谢谢
答案 0 :(得分:5)
您的应用可以覆盖- (void)applicationWillEnterForeground:(UIApplication *)application
中的UIApplicationDelegate
。
您还可以让您的控制器成为UIApplicationWillEnterForegroundNotification的观察者。根据Apple Docs:在应用程序离开后台状态之前不久发布,即成为活动应用程序。
NIB文件中带控制器的示例代码,否则覆盖- (id)init
:
- (void)awakeFromNib {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wakeUp:) name:UIApplicationWillEnterForegroundNotification object:nil];
}
- (void)wakeUp:(NSNotification *)pNotification {
NSLog(@"Name: %@", [pNotification name]);
NSLog(@"Object: %@", [pNotification object]);
NSLog(@"I am waking up");
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
答案 1 :(得分:4)
查看applicationDidBecomeActive
协议中applicationWillEnterForeground
和UIApplicationDelegate
的文档:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html