您的位置:首页 > 其它

传感器 - 距离传感器

2015-09-23 18:23 211 查看
// 距离传感器

// 温度传感器

// 磁力传感器

// 光传感器

// 湿度传感器

// 陀螺仪 -- 导航, 赛车游戏(角速度传感器)

// 运动传感器 - 加速度传感器 -- 摇一摇, 计步器

//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// 距离传感器 - 默认是关闭的

// 1. 开启距离传感器 - 开启之后就会实时监听

[UIDevice currentDevice].proximityMonitoringEnabled = YES;

// 2. 当监听到有物体靠近设备时, 会调用通知

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ProximityStateDidChanged:) name:UIDeviceProximityStateDidChangeNotification object:nil];

}

- (void)ProximityStateDidChanged:(NSNotification *)noticefication

{

LogRed(@"%@",noticefication);

if ([UIDevice currentDevice].proximityState){

LogGreen(@"靠近-----靠近");

}else{

LogMagenta(@"离开 --- 离开");

}

}

- (void)dealloc

{

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceProximityStateDidChangeNotification object:nil];

}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: