이 기능을 App에서 이용을 하기 위해서, 아래와 같이 설정하는 것이 필요하다.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[[NSNotificationCenter defaultCenter] addObserverForName:UIDeviceProximityStateDidChangeNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note) {
NSLog(@"The Proximity sensor(%@)", [UIDevice currentDevice].proximityState?@"On":@"Off");
NSLog(@"name:%@, userInfo:%@", note.name, note.userInfo);
}];
}
센서를 ON 하기 위해서는 아래와 같이 값을 설정한다.
BOOL isEnabled = [UIDevice currentDevice].proximityMonitoringEnabled;
[UIDevice currentDevice].proximityMonitoringEnabled = !isEnabled;
근접센서는 iPhone에서는 동작이 되지만, iPad에서는 설정을 해도 계속 NO가 된다.
즉, iPad에는 근접센서가 없다.
0 comments:
댓글 쓰기