//I have created below snippet to let the sensor to be detected.
-(void)addProximitySensorControl {
UIDevice *device = [UIDevice currentDevice];
device.proximityMonitoringEnabled = YES;
BOOL state = device.proximityState;
if(state)
NSLog(@"YES");
else
NSLog(@"NO");
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(proximityChanged:)
name:@"UIDeviceProximityStateDidChangeNotification"
object:nil];
}
在iPhone 3GS或更早版本中proximityChanged:方法被成功调用,但在iPhone 4中,当我悬停物体时,传感器(屏幕)没有被检测到。任何想法的人?接近传感器无法在iPhone 4设备上工作
此代码检查设备是否接近某些事物('proximityState'),而不是它是否存在('isProximityMonitoringEnabled')。 – 2013-03-01 12:58:55