系統通知
- (void)viewDidLoad {
[superview DidLoad];
//從后臺進入前臺的通知
//UIApplicationWillEnterForegroundNotification應用從后臺將要進入前臺(活動狀態)的時候
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Method1) name:UIApplicationWillEnterForegroundNotification object:nil];
//進入后臺的通知
//UIApplicationDidEnterBackgroundNotification應用將要進入后臺(失去活動狀態)的時候
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Method2) name:UIApplicationDidEnterBackgroundNotification object:nil];
//UIApplicationWillResignActiveNotification將要取消活躍狀態
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Method3) name:UIApplicationWillResignActiveNotification object:nil];
//UIApplicationDidBecomeActiveNotification應用進入活躍狀態
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Method4) name:UIApplicationDidBecomeActiveNotification object:nil];
//UIApplicationWillTerminateNotification被動終止(比如來電)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(Method5) name:UIApplicationWillTerminateNotification object:nil];
}
- (void)Method1 {
NSLog(@"應用進入前臺(活動狀態)的時候");
}
- (void)Method2 {
NSLog(@"應用將要進入后臺(失去活動狀態)的時候");
}
- (void)Method3 {
NSLog(@"將要取消活躍狀態");
}
- (void)Method4 {
NSLog(@"應用進入活躍狀態");
}
- (void)Method5 {
NSLog(@"UIApplicationWillTerminateNotification");
}