Skip to content

Instantly share code, notes, and snippets.

@HituziANDO
Last active December 20, 2015 15:38
Show Gist options
  • Save HituziANDO/6155240 to your computer and use it in GitHub Desktop.
Save HituziANDO/6155240 to your computer and use it in GitHub Desktop.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self startSensor];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self stopSensor];
}
~~~ 省略 ~~~
#pragma mark - Proximity Sensor
- (void)startSensor
{
[UIDevice currentDevice].proximityMonitoringEnabled = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityStateDidChange:) name:UIDeviceProximityStateDidChangeNotification object:nil];
}
- (void)stopSensor
{
[UIDevice currentDevice].proximityMonitoringEnabled = NO;
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceProximityStateDidChangeNotification object:nil];
}
/**
* 画面消灯は近接センサをONにするだけで実装されている
*/
- (void)proximityStateDidChange:(NSNotification *)notification
{
// センサに近づいたら
if ([UIDevice currentDevice].proximityState == YES) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment