距离传感器的使用
//开启距离感应功能
[UIDevice currentDevice].proximityMonitoringEnabled = YES;
//监听距离感应的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityChange:)
name:UIDeviceProximityStateDidChangeNotification object:nil];
- (void)proximityChange:(NSNotificationCenter *)notification {
if ([UIDevice currentDevice].proximityState==YES){
NSLog(@"某个物体靠近了设备屏幕");//屏幕会自动锁住
}else{
NSLog(@"某个物体远离了设备屏幕");//屏幕会自动解锁
}
}
网友评论