NSNotification 系統通知

系統通知

- (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");

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容