现在的位置: 首页 > 综合 > 正文

iPhone近身传感器监测

2013年07月16日 ⁄ 综合 ⁄ 共 1343字 ⁄ 字号 评论关闭

 

The proximity sensor on the iPhone detects when the device is close to your face (or otherwise covered). There aren’t many times when using the sensor is of value, however, the Google Voice Search application has put this to good use as a means to trigger voice recording for a search request. If you have an interest in doing something similar, read on.

Proximity Sensor Monitoring

It all begins by enabling proximity monitoring, this is followed by setting up a notification request to call a method when the proximity state changes:

 

The method below will be called when the sensor state is updated, a message is printed to the debug console based on the sensor proximity.

 

Detecting Proximity Sensor

Not all iOS device have proximity sensors. The Apple API documentation states that you should enable proximity monitoring and check the proximityState, if the return value is NO, then the device does not have a sensor.

I was unable to successfully use this approach to determine if a device has a sensor. Any additional ideas or suggestions are welcome.

 

 

抱歉!评论已关闭.