[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sensorStateChange:)
name:@"UIDeviceProximityStateDidChangeNotification"
object:nil];
-(void)sensorStateChange:(NSNotificationCenter *)notification;
{
if ([[UIDevice currentDevice] proximityState] == YES) {
NSLog(@"Device is close to user");
}else{
NSLog(@"Device is not close to user");
}
}
转载于:https://www.cnblogs.com/ligun123/archive/2012/01/04/2311897.html