Wednesday, April 04, 2012

Proximity Sensor use in iPhone

// Enabled monitoring of the sensor
[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
 
// Set up an observer for proximity changes
[[NSNotificationCenter defaultCenter] addObserver:self
                selector:@selector(sensorStateMonitor:) 
         name:@"UIDeviceProximityStateDidChangeNotification" 
                object:nil];
 
- (void)sensorStateMonitor:(NSNotificationCenter *)notification
{
  if ([[UIDevice currentDevice] proximityState] == YES)
    NSLog(@"Device is close to user.");
  else 
    NSLog(@"Device is not closer to user.");
}
 

No comments:

Swift Operators - Basic Part 3 (Range operators in swift)

Range Operators: Closed Range operators  Half-Open Range Operators One-Sided Ranges Closed Range Operators:  a...b It defines...