IT tutorials
 
Mobile
 

iphone Programming : Using Sensors - Accessing the Proximity Sensor

1/8/2013 11:22:53 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

The proximity and ambient light sensors are two separate sensors. The ambient light sensor is used to change the brightness level of the device’s screen automatically, while the proximity sensor is used by the device to turn the screen off when you put the phone to your ear to make a call. Although it does have an ambient light sensor, the iPod touch does not have a proximity sensor.

Unfortunately, there is no way to access the ambient light sensor in the official SDK. However, developers can access the proximity sensor via the UIDevice class. This sensor is an infrared LED emitter/detector pair positioned near the earpiece, as shown in Figure 1. It measures the return reflection of the transmitted infrared beam to detect (large) objects near the phone.

Figure 1. The IR LED of the proximity sensor is located near the earpiece


You can enable the sensor in your application by toggling the proximityMonitoringEnabled Boolean:

UIDevice *device = [UIDevice currentDevice];
device.proximityMonitoringEnabled = YES;

You can query whether the proximity sensor is close to the user:

BOOL state = device.proximityState;

If proximity monitoring is enabled, a UIDeviceProximityStateDidChangeNotification notification will be posted by the UIDevice when the state of the proximity sensor changes; you can ask that your application is notified when this occurs by registering your class as an observer with the notification center:

[[NSNotificationCenter defaultCenter]
  addObserver:self selector:@selector(proximityChanged:)
  name:@"UIDeviceProximityStateDidChangeNotification" object:nil];

Notifications would then get received by the proximityChanged: method:

- (void) proximityChanged: (NSNotification *)note {
   UIDevice *device = [note object];
   NSLog(@"In proximity: %i", device.proximityState);
}
 
Others
 
- Mobile Web Apps : Templating - Twitter Integration with Templating
- Mobile Web Apps : Ajax - Fetching HTML, Ajaxifying Links
- IPad : Working with Contacts - Adding a New Contact Right on Your iPad
- Bluetooth on the iPad : Bluetooth Stereo, Disconnect or Forget a Bluetooth Device
- BlackBerry Bold 9700 and 9650 Series : Fixing Problems - Web Browser Running Slowly, Automatic Memory Cleaning to Keep Running Smoothly
- BlackBerry Bold 9700 and 9650 Series : Fixing Problems - BlackBerry Running Slowly?
- Windows Phone 7 Advanced Programming Model : Working with Images on Windows Phone 7, The Windows Phone 7 Media Library
- Windows Phone 7 Advanced Programming Model : Encryption Services
- Debugging Android Applications : Eclipse Java Editor (part 5) - Traceview
- Debugging Android Applications : Eclipse Java Editor (part 4) - Android Debug Bridge, Dalvik Debug Monitor Service
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us