根据在网上查到的资料,应该这样实现
UIDevice *device = [UIDevice currentDevice];
device.proximityMonitoringEnabled=YES;
NSLog(@"ningman: %hhd",device.proximityMonitoringEnabled);
NSLog(@"ningman: %hhd",device.proximityState);
//device.proximityMonitoringEnabled=YES; // 允许临近检测
// 临近消息触发
[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityChanged:) name:UIDeviceProximityStateDidChangeNotification object:device];
- (void) proximityChanged:(NSNotification *)notification
{
UIDevice *device = [notification object];
NSLog(@"In proximity:%i",device.proximityState);
if(device.proximityState==1)
{
//do something
}
}
可是我这样做,怎么也捕获不到事件,大大们指路啊(我是在daemon程序中捕获)。在普通app中可以捕获。困惑中。。。