iOS距离传感器的简单使用

2017-10-26  本文已影响0人  没有故事的我
// 打开距离传感器
[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(@"有东西离开");
    }
}
上一篇 下一篇

猜你喜欢

热点阅读