- (void)viewDidLoad {
[super viewDidLoad];
// 距离传感器的开关 只要打开就可以检测是否靠近屏幕
// 应用场景 : 微信语音
[UIDevice currentDevice].proximityMonitoringEnabled = YES;
// 代理 通知 等
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(proximityMonitoringMathod:) name:UIDeviceProximityStateDidChangeNotification object:nil];
}
- (void)proximityMonitoringMathod:(NSNotification *)noti{
if ([UIDevice currentDevice].proximityState) {
NSLog(@"近了!");
}else{
NSLog(@"远了!");
}
}
网友评论