根据光线感应关闭和开启屏幕

根据光线感应关闭和开启屏幕

UIDevice *_curDevice = [UIDevice currentDevice];

    [_curDevice setProximityMonitoringEnabled:YES];

    NSNotificationCenter *_defaultCenter = [NSNotificationCenter defaultCenter];

    [_defaultCenter addObserverForName:UIDeviceProximityStateDidChangeNotification

                                object:nil

                                 queue:[NSOperationQueue mainQueue]

                            usingBlock:^(NSNotification *note) {

                                if (_curDevice.proximityState == YES) {

                                    NSLog(@"怕是黑屏了吧");

                                }

                                else {

                                    NSLog(@"屏幕应该亮了");

                                }

                            }];

posted on 2015-09-10 18:06  廖利君  阅读(232)  评论(0编辑  收藏  举报