iOS 监听 出发 Home键 NSNotificationCenter UIApplicationWillResignActiveNotification
ios 监听 home 出发
2023-09-27 14:22:41 时间
第一步:
创建2个NSNotificationCenter监听
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotificationobject:nil];//监听是否触发home键挂起程序. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotificationobject:nil];//监听是否重新进入程序程序.
第二步:
实现2个NSNotificationCenter所触发的事件方法
-(void)applicationWillResignActive:(NSNotification*)notification { printf("按理说是触发home按下\n"); } -(void)applicationDidBecomeActive:(NSNotification*)notification { printf("按理说是重新进来后响应\n"); }
注: 在home键触发后,AppDelegate响应的方法为:
-(void)applicationDidEnterBackground:(UIApplication*)application { /* Use this method to release shared resources, save user data, invalidate timers,
and store enough application state information to restore your application to its current state in case it is terminated later. If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. */ }
相关文章
- IOS文件操作的两种方式:NSFileManager操作和流操作
- 【短视频SDK】关于iOS提供的SDK中模拟器版本(debug)和release 版本
- 国内90%以上的 iOS 开发者,对 APNs 的认识都是错的
- iOS transform属性的使用
- iOS常用第三方库
- gitlab+jenkins自动化打包IOS-jenkins配置
- ios之CABasicAnimation
- Flutter与Android iOS 的双向通信
- 二维码合成,将苹果和安卓(ios和android)合成一个二维码,让用户扫描一个二维码就可以分别下载苹果和安卓的应用
- 李洪强漫谈iOS开发[C语言-050]-doWhile统计用户输入字符
- 【零基础学习iOS开发】【02-C语言】05-进制
- 李洪强iOS开发之OC语言description方法和sel
- iOS开发多线程篇 08 —GCD的常见用法
- iOS 原生模块 给 Javascript(ReactNative) 发送事件 (通知监听)
- IOS网络请求Get,Post请求差异及用法