2013-08-23 3 views
1

사용자가 근접 센서를 손으로 움직일 때 근접 센서를 켜고 0과 같은 근접 상태 값을 얻고 싶다는 점에서 하나의 앱을 개발 중입니다. 사용자가 손을 움직이면 두 번째 시간 값은 1이됩니다. 내가 어떻게 할 수 있습니다 근접을 활성화하는 방법을 알고 있지만 사용자가 프록시 주위에 손을 이동할 때 근접성을 사용하고 싶습니다. 그래서 내가 어떻게이 코드를 시도 할 수 있습니다. 근접성을 가능하게합니다. 내가 proximit에서 사용자 HND 당이 코드를 통해 할 것주변 센서가 손을 움직일 때 센서가

-(void)handleProximityChange:(NSNotification *)notification 
{ 

    NSLog(@"Proximity event catch"); 

} 

UIDevice * device=[UIDevice currentDevice]; 
    device.proximityMonitoringEnabled=YES; 

    if (device.proximityMonitoringEnabled) 
    { 
     [[NSNotificationCenter defaultCenter] addObserver:self 
               selector:@selector(handleProximityChange:) 
                name:UIDeviceProximityStateDidChangeNotification 
             object:nil]; 
    } 
    else 
    { 
     NSLog(@"Device not capable to support Proximity sensor"); 
     // device not capable 
    } 

및이 방법에 근접 상태를 잡을

은 ... 괭이, 그래서 나는이 이렇게 저를 도와주세요 할 수 있습니다.

답변

3
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    count = 0; 
    condition = 0; 
    [self addProximitySensorControl]; 
} 

-(void)addProximitySensorControl { 

    UIDevice *device = [UIDevice currentDevice]; 
    device.proximityMonitoringEnabled = YES; 

    BOOL state = device.proximityState; 
    if(state) 
    { 
     NSLog(@"YES"); 
     _sensorSupport.text = @"YES"; 
    } 
    else 
    { 
     NSLog(@"NO"); 
    _sensorSupport.text = @"No"; 
    } 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(proximityChanged:) 
               name:@"UIDeviceProximityStateDidChangeNotification" 
               object:nil]; 
} 
-(void)proximityChanged:(NSString*)str 
{ 
    NSLog(@"i am in proximityChanged"); 
    condition++; 
    if (condition % 2 == 0) { 
     count++; 
    } 
    _counter.text = [NSString stringWithFormat:@"%d",count]; 
} 
+0

답장을 보내 주셔서 감사합니다 ... – Jitendra

+0

처음으로 손을 움직일 때 근접 거리를 입력 한 다음 근접 값을 입력하면됩니다. 그리고 나는 카운터 1을 설정하지 않아도됩니다. – Jitendra

+0

@Ashwinkumar 코드만으로 대답하면 질문에 대한 대답이 될 수도 있지만, 당신이 무엇을 바꿨는지, 왜 그 이유가 무엇인지에 대해 최소한의 소개 만 있으면 유용합니다. – Sumurai8