标签:device sts enter 打开 距离 set from ios 智能手机
● 运动传感器\加速度传感器\加速计(Motion/Accelerometer Sensor)
● 环境光传感器(Ambient Light Sensor)
● 距离传感器(Proximity Sensor)
● 磁力计传感器(Magnetometer Sensor)
● 内部温度传感器(Internal Temperature Sensor)
● 湿度传感器(Moisture Sensor)
● 陀螺仪(Gyroscope)
- (void)proximityChange:(NSNotificationCenter *)notification {
if ([UIDevice currentDevice].proximityState == YES) {
NSLog(@"某个物体靠近了设备屏幕"); // 屏幕会自动锁住
} else {
NSLog(@"某个物体远离了设备屏幕"); // 屏幕会自动解锁
} }
//打开距离感应功能
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // 1.开启距离传感器(注意: 默认情况距离传感器是关闭的) // [UIApplication sharedApplication].proximitySensingEnabled = YES; // 只要开启之后, 就开始实时监听 [UIDevice currentDevice].proximityMonitoringEnabled = YES; // 2.当监听到有物体靠近设备时系统会发出通知 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityStateDidChange:) name:UIDeviceProximityStateDidChangeNotification object:nil]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } // 当监听到有物体靠近设备时调用 - (void)proximityStateDidChange:(NSNotification *)note { // NSLog(@"%@", note); if( [UIDevice currentDevice].proximityState) { NSLog(@"有物体靠近"); }else { NSLog(@"物体离开"); } } @end
标签:device sts enter 打开 距离 set from ios 智能手机
原文地址:http://www.cnblogs.com/liuwj/p/6869983.html