#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//开启距离传感器检测
[UIDevice currentDevice].proximityMonitoringEnabled = true;
//添加<span style="font-family: Arial, Helvetica, sans-serif;">距离传感器距离</span><span style="font-family: Arial, Helvetica, sans-serif;">改变的通知</span>
[[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];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
传感器--------接近传感器
最新推荐文章于 2023-07-05 15:54:03 发布