Proximity Sensor无法在iPhone 4设备中运行

Kul*_*eep 6 iphone ios proximitysensor

//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];
}
Run Code Online (Sandbox Code Playgroud)

在iPhone 3GS或更早版本的proximityChanged:方法被成功调用,但在iPhone 4中,当我从上方悬停物体时,传感器(屏幕)未被检测到.任何想法伙计们?

Kru*_*lur 1

您的代码没有任何问题(当然假设您proximityChanged:确实实现了)。我在 iPhone 4 上测试了你的代码,它对我的​​手在接近传感器前面移动做出了响应。

也许 3GS 的硬件略有不同,这意味着它对您所做的事情更敏感?您可以尝试使用不同的 iPhone 4 设备(或者至少验证接近传感器是否正常工作,例如通过使用手机应用程序)?