我想在不关闭显示屏的情况下拦截接近传感器。
I want to intercept the proximity sensor without turning off the display.
据我所知,我有两个Bool变量:
I know by the documentation that I have two Bool variables:
proximityMonitoringEnabled proximityState和此代码
[UIDevice currentDevice].proximityMonitoringEnabled = YES;当接近传感器检测到某些东西时,它会关闭显示屏,就像你持有时一样通过电话拨打电话。
When the proximity sensor detects something it turns off the display, same way it does when you're holding the phone to your ear when on a phone call.
当接近传感器被遮盖时如何保持显示器开启?
How do I keep the display on when the proximity sensor is covered?
推荐答案Apple的文档指出并非所有iPhone OS设备都有接近传感器。要确定您的应用程序运行的设备是否支持接近监控,请将proximityMonitoringEnabled属性设置为YES,然后检查它的值:
Apple’s documentation notes that "Not all iPhone OS devices have proximity sensors." To determine if the device your app is running supports proximity monitoring, set the proximityMonitoringEnabled property to YES, then check its value:
UIDevice *device = [UIDevice currentDevice]; [device setProximityMonitoringEnabled:YES]; if (device.proximityMonitoringEnabled == YES) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityChanged:) name:@"UIDeviceProximityStateDidChangeNotification" object:device]; } - (void) proximityChanged:(NSNotification *)notification { UIDevice *device = [notification object]; NSLog(@"In proximity: %i", device.proximityState); }资料来源: www.whatsoniphone/blog/new-in-iphone-30 -tutorial-series-part-4-proximity-detection /
将有助于检测传感器的当前状态。
Will help to detect current state of sensor.
允许屏幕变暗的公共API:
Public API that allows screen dim:
[UIScreen mainScreen].wantsSoftwareDimming = YES; [UIScreen mainScreen].brightness = $your_brightness_value;在此处找到:在iOS 6中更改为wantsSoftwareDimming?
更多推荐
覆盖接近传感器时保持显示
发布评论