一、常见传感器:

    运动传感器\加速度传感器\加速计Motion/Accelerometer Sensor

  环境光传感器(Ambient Light Sensor)//很老的了 感受周围环境光线的强弱

  距离传感器(Proximity Sensor)//感应是否有其他物体靠近

  磁力计传感器(Magnetometer Sensor)//磁场

  内部温度传感器(Internal Temperature Sensor)//设备内部温度

  湿度传感器(Moisture Sensor)//是否进水等

  陀螺仪(Gyroscope)//主要判断角度,飞车游戏等

1、距离传感器,必须使用真机测试

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 距离传感器默认是关闭(实时的检测是否有物品靠近,所有非常耗电)
    // [UIApplication sharedApplication].proximitySensingEnabled
    [UIDevice currentDevice].proximityMonitoringEnabled = YES;
    
    // 通过通知(一旦有物品靠近或者离开的时候,都会发出通知)
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityStateDidChange) name:UIDeviceProximityStateDidChangeNotification object:nil];
}
// 当有物品靠近或者离开的时候会调用该方法
- (void)proximityStateDidChange{
    if ([UIDevice currentDevice].proximityState) {
        NSLog(@"有物品靠近");
    } else {
        NSLog(@"有物品离开");
    }
}
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

 

posted on 2015-11-20 10:19  怡情_老二  阅读(370)  评论(0)    收藏  举报