iphone怎么检测屏幕是否被点亮 (用UIApplication的Delegate)
本文转载至 http://gaohaijun.blog.163.com/blog/static/176698271201161524857373/
要用那个api ,给点提示 谢谢了。 复制代码
|
没有测试,但是相信可以。
刚刚测试,假如是子类化UIApplication是无法接受到这个方法的。用Objc Runtime的method_exchangeImplementations(method, method)就可以。
以下代码:
UIApplication方面:
|
UIApplicationDelegate:
|
以上代码在打开后关闭屏幕再打开的条件下输出:
引用
2009-08-17 19:05:37.770 *[380:207] Application did become active.
2009-08-17 19:06:36.370 *[380:207] Did turn off display.
2009-08-17 19:06:36.452 *[380:207] Application will resign active.
2009-08-17 19:06:43.310 *[380:207] Did turn on display.
2009-08-17 19:06:43.415 *[380:207] Application did become active.
可见这个是方法在delegate的willResignActive和didBecomeActive之前调用。
其实屏幕在变黑时, 会通知程序
- (void)applicationWillResignActive:(UIApplication *)application;
而解锁后变亮会触发
- (void)applicationDidBecomeActive:(UIApplication *)application;
- (void)applicationWillResignActive:(UIApplication *)application;
而解锁后变亮会触发
- (void)applicationDidBecomeActive:(UIApplication *)application;