iOS基础-加速器使用1

iOS基础开发教程--加速器的使用1

加速器使用注意:

  1. 允许接近显示屏
  2. 发送通知
- (void)viewDidLoad{
    [super viewDidLoad];
       [UIDevice currentDevice].proximityMonitoringEnabled = YES; 
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityStateDidChange:) name:UIDeviceProximityStateDidChangeNotification object:nil];
   }
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];}- (void)proximityStateDidChange:(NSNotification *)noti{
    if ([UIDevice currentDevice].proximityState) {
        NSLog(@"有物体靠近当前设备");
    } else { 
       NSLog(@"有物体离开当前设备");
    }}

你可能感兴趣的:(iOS基础-加速器使用1)