Using the Proximity Sensor
suggest change//Enabling the proximity Sensor
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
[[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 close to user.");
}
}
The selector receives an NSNotification, but the parameter is declared as NSNotificationCenter * (it is unused). The observer is not removed when the view disappears.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents