//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