不知道是应该叫红外感应还是应该叫什么,就是打电话的时候会自动黑屏的那个API,原来没注意过。
UIDevice *_curDevice = [UIDevice currentDevice];
[_curDevice setProximityMonitoringEnabled:YES];
NSNotificationCenter *_defaultCenter = [NSNotificationCenter defaultCenter];
[_defaultCenter addObserverForName:UIDeviceProximityStateDidChangeNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
if (_curDevice.proximityState == YES) {
NSLog(@"怕是黑屏了吧");
}
else {
NSLog(@"屏幕应该亮了");
}
}];
[_curDevice setProximityMonitoringEnabled:YES];
NSNotificationCenter *_defaultCenter = [NSNotificationCenter defaultCenter];
[_defaultCenter addObserverForName:UIDeviceProximityStateDidChangeNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
if (_curDevice.proximityState == YES) {
NSLog(@"怕是黑屏了吧");
}
else {
NSLog(@"屏幕应该亮了");
}
}];
转载请注明: 转自Rainbird的个人博客 本文链接: iOS红外感应