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

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容