近接センサー


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // 近接センサーを使用する
  2. [UIDevice currentDevice].proximityMonitoringEnabled = YES;
  3.  
  4. // 変更の通知を受け取るメソッドの登録
  5. [[NSNotificationCenter defaultCenter]
  6. addObserver: self
  7. selector:@selector(proximityStateDidChange: )
  8. name:UIDeviceProximityStateDidChangeNotification
  9. object:nil];
  10.  
  11. // 近接センサーの状態変更時に呼び出されるメソッド
  12. - (void) proximityStateDidChange:(NSNotification *)notification{
  13. NSLog(@"%s",__PRETTY_FUNCTION__);
  14. NSLog(@"state = %@",
  15. [UIDevice currentDevice].proximityState ? @"YES":@"NO");
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.