Skip to content

Instantly share code, notes, and snippets.

@donly
Created May 25, 2012 06:13
Show Gist options
  • Save donly/2786100 to your computer and use it in GitHub Desktop.
Save donly/2786100 to your computer and use it in GitHub Desktop.
// 添加通知
[[UIDevice currentDevice] setProximityMonitoringEnabled:YES];
if ([UIDevice currentDevice].proximityMonitoringEnabled == YES)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(proximitySensorChange:)
name:UIDeviceProximityStateDidChangeNotification
object:nil];
// 移除通知
if ([UIDevice currentDevice].proximityMonitoringEnabled == YES)
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIDeviceProximityStateDidChangeNotification
object:nil];
[[UIDevice currentDevice] setProximityMonitoringEnabled:NO];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment