传感器:用来检测周边的信息。不同类型的传感器检测效果也不同
传感器类型:运动、加速器、。。。等等
使用步骤
1.开启距离传感器,默认时距离传感器是关闭的,这个方法已经不用了
[UIApplication sharedApplication].proximitySensingEnabled = YES;
1.开启之后就开始实时监听(使用最新的方法)
[UIDevice currentDevice].proximityMonitoringEnabled = YES;
2.当监听到有物体靠近时发送通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
3.将通知delloc
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
4.实现距离传感器的方法
-(void)proximityDidChange:(NSNotification *)note{
if( [UIDevice currentDevice].proximityMonitoringEnabled){
//有物体
}else{
//没物体
}
}