2016-07-22 15 views
0

사용자가 두 가지 방법으로 헤드폰 키를 눌렀는지 감지하려고합니다. 헤드폰 키를 감지하는 방법?

-(void)headsetMicrophoneDetection 
{ 
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 
    [[MPRemoteCommandCenter sharedCommandCenter].togglePlayPauseCommand addTarget:self action:@selector(onTooglePlayPause)]; 

    NSLog(@"calling headset method"); 
} 
-(void)onTooglePlayPause 
{ 
    NSLog(@"kishore"); 
} 
- (void)remoteControlReceivedWithEvent:(UIEvent *)theEvent 
{ 
    NSLog(@"callig method to :)"); 
    if (theEvent.type == UIEventTypeRemoteControl) { 
     switch(theEvent.subtype) { 
      case UIEventSubtypeRemoteControlTogglePlayPause: 
       NSLog(@"Hello"); 
       break; 
      case UIEventSubtypeRemoteControlPlay: 
       NSLog(@"Hello 2"); 
       break; 
      case UIEventSubtypeRemoteControlPause: 
       NSLog(@"Hello 3"); 
       break; 
      case UIEventSubtypeRemoteControlStop: 
       NSLog(@"Hello 4"); 
       break; 
      default: 
       return; 
     } 
    } 
} 

하지만 난이에게 NSObject의 클래스의 모든 메소드를 사용하고 난 오디오 체크 &에 대한 백그라운드 서비스를 사용할 수 뭐죠 내 코드에서 잘못된 내가 얻을 did't이 메소드를 호출 한 후

.

+0

누락 되었습니까? MPRemoteCommandCenter에 대한 선택기를 정의 할 때 선택기에 매개 변수가 필요합니까? – ldindu

+0

@ldindu 아니오 나는 –

답변

0

아래 코드를 확인하십시오.

- (BOOL)isHeadsetPluggedIn { 
    AVAudioSessionRouteDescription* route = [[AVAudioSession sharedInstance] currentRoute]; 
    for (AVAudioSessionPortDescription* desc in [route outputs]) { 
     if ([[desc portType]  isEqualToString:AVAudioSessionPortHeadphones]) 
      return YES; 
    } 
    return NO;} 
+0

을 놓치지 않았지만 사용자가 버튼 볼륨을 누르는 지 확인하고 싶습니다. 게시물에 대한 재생/일시 중지 감사 :) –