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:

Create a list in SwiftUI with sticky section headers

 Sample Code import SwiftUI struct ContentView : View {     @State var isCustomViewControllerDisplayed = false     @State private va...