2017-05-20 8 views
0

내가 VOIP 통화를 위해 PJSIP를 사용하여 아이폰 OS 응용 프로그램을 설계하고, 마이크가 있지만 스피커 버튼을 누른 후 스피커에서 다시들을 수 없습니다.스피커/VOIP 통화 중 정상 마이크 프로그래밍 방식으로 아이폰 OS 10 신속한 나는 스피커에 전화를 시작하고 버튼을 눌러에 내가 정상에 전화를 걸 수 있어요 <p></p>

내가 그 기능을 달성하기 위해 다음 코드를 사용했다 : -

if sender.titleLabel?.text == "Speaker"{ 

      do { 
       try audioSession.overrideOutputAudioPort(.none) 
       try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord) 
       try audioSession.setMode(AVAudioSessionModeVoiceChat) 
       try audioSession.setActive(true) 
      } catch { 
       print("AVAudioSession cannot be set: \(error)") 
      } 
     }else{ 
      do { 
       try audioSession.overrideOutputAudioPort(.speaker) 
       try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord) 
       try audioSession.setMode(AVAudioSessionModeVoiceChat) 
       try audioSession.setActive(true) 
      } catch { 
       print("AVAudioSession cannot be set: \(error)") 
      } 
     } 

답변

0

임 확실하지하지만 난 NSNotificationCenter를 사용하는 동안 코드가 작동 것이라 생각합니다. if 문에 발표자에 대한 알림 및 해당 else 코드에 대한 알림을 보냅니다. 버튼을 누르면 동작에

거짓

VAR 스피커 =있는 viewDidLoad에

if speaker == false { 
    NSNotificationCenter.defaultCenter().postNotificationName("speakerON", object: nil) 

} else { 
    NSNotificationCenter.defaultCenter().postNotificationName("speakerOFF", object: nil) 

} 

:

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(YourClassName.methodOfReceivedNotification(_:)), name:"speakerON", object: nil) 

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(YourClassName.methodOfReceivedNotification(_:)), name:"speakerOFF", object: nil) 

당신의 기능을 다음과 같은 경우

func speakerON() { 
try audioSession.overrideOutputAudioPort(.none) 
       try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord) 
       try audioSession.setMode(AVAudioSessionModeVoiceChat) 
       try audioSession.setActive(true) 
} 

func speakerOFF() { 
       try audioSession.overrideOutputAudioPort(.speaker) 
       try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord) 
       try audioSession.setMode(AVAudioSessionModeVoiceChat) 
       try audioSession.setActive(true) 
} 

이 링크를 참조하시기 바랍니다 ~ 싶다 NSNotificationCenter에 대한 자세한 내용은

https://stackoverflow.com/questions/24049020/nsnotificationcenter-addobserver-in-swift