iOS如何检测app从后台调回前台

时间:2025-02-18 18:05:14

当按Home键,将应用放在后台之后,然后再次调用回来的时候,回出发AppDelegate里面的一个方法,-(void)applicationWillEnterForeground.

当应用再次回到后台就会执行该方法,所以监听 UIApplicationWillEnterForegroundNotification这条通知就可以获取返回前台的操作了.

 UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter]addObserverForName:UIApplicationWillEnterForegroundNotification object:app queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
NSLog(@"Enter Foreground");
}];