您的当前位置:首页正文

ios开发 息屏

来源:华拓网

[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sensorStateChange:)
name:@"UIDeviceProximityStateDidChangeNotification"
object:nil];

-(void)sensorStateChange:(NSNotificationCenter *)notification;
{
if ([[UIDevice currentDevice] proximityState] == YES) {
NSLog(@"屏幕熄灭");
}else{
NSLog(@"屏幕亮起");
}
}