距离感应

距离感应器其实就那么几句话:

    [UIDevice currentDevice].proximityMonitoringEnabled = YES;
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(noticeReceive) name:UIDeviceProximityStateDidChangeNotification object:nil];



-(void)noticeReceive{
    
    
    if ([UIDevice currentDevice].proximityState) {
        NSLog(@"近距离,做你想做的");
      
    }else{
        NSLog(@"远距离");
    }
}


但要注意:感应器只有在竖屏的时候管用,当你的设备横屏时,抱歉,距离感应over..................千万注意

你可能感兴趣的:(swift,ios)