距离传感器的使用

- (void)ViewDidLoad { 
// 打开距离传感器,开启距离检测功能
    [UIDevice currentDevice].proximityMonitoringEnabled = YES;

// 监听距离改变 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityStateDidChange:) name:UIDeviceProximityStateDidChangeNotification object:nil]; } - (void)proximityStateDidChange:(NSNotification *)note { if ([UIDevice currentDevice].proximityState) { NSLog(@"有物体靠近设备屏幕"); } else { NSLog(@"有物体远离设备屏幕"); } }
原文地址:https://www.cnblogs.com/cdp-snail/p/4941975.html