iOS距离传感器的简单使用

2016-06-17  本文已影响1623人  Young_Blood
// 打开距离传感器
[UIDevice currentDevice].proximityMonitoringEnabled = YES;

// 通过通知监听有物品靠近还是离开
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityStateDidChange:) name:UIDeviceProximityStateDidChangeNotification object:nil];

- (void)proximityStateDidChange:(NSNotification *)note
{
    if ([UIDevice currentDevice].proximityState) {
        NSLog(@"有物品靠近");
    } else {
        NSLog(@"有物品离开");
    }
}
上一篇 下一篇

猜你喜欢

热点阅读