2017-08-02 4 views
1

次のコードを使用して、使用可能な出力を検出していますが、接続されているBluetoothデバイスが認識されません。私はそれから音楽を演奏しているので、私のBluetoothデバイスが正しく接続されていることを知っています。AVAudioSessionが接続されたBluetoothデバイスを検出していません

let session = AVAudioSession.sharedInstance() 
     for description in session.currentRoute.outputs { 
      if description.portType == AVAudioSessionPortHeadphones { 
       NSLog("headphone plugged in") 
       let alertActin = UIAlertAction(title: "Headphones", style: UIAlertActionStyle.default, handler:nil) 
       alertActin.setValue(UIColor.blue, forKey: "titleTextColor") 
       alert.addAction(alertActin) 
      } else if description.portType == AVAudioSessionPortBluetoothA2DP { 
       NSLog("Bluetooth plugged in") 

       let alertActin = UIAlertAction(title: description.portName, style: UIAlertActionStyle.default, handler:nil) 
       alertActin.setValue(UIColor.blue, forKey: "titleTextColor") 
       alert.addAction(alertActin) 
      } else if description.portType == AVAudioSessionPortBluetoothLE { 
       NSLog("Bluetooth plugged in") 

       let alertActin = UIAlertAction(title: description.portName, style: UIAlertActionStyle.default, handler:nil) 
       alertActin.setValue(UIColor.blue, forKey: "titleTextColor") 
       alert.addAction(alertActin) 
      } 
      else { 
       NSLog("") 
      } 
     } 

答えて

0

hereのように、最初にAVAudioSessionにBluetooth出力を許可するよう指示する必要があります。

this postは、AVAudioSessionCategoryPlayAndRecordを使用しないことを念頭に置いてください。また、出力デバイスを操作する際はAVAudioSessionCategoryPlaybackを使用することをお勧めします。

+0

は、私は私のコードにこれを追加私のBluetoothスピーカーはまだやるが表示されない{ \t \t \t session.setCategory(とAVAudioSessionCategoryPlayAndRecord、:[.allowBluetooth])をしてみてください \t \t \tしてみてくださいsession.setActive(真) \t \t}キャッチ{ \t \t \t致命( "エラーがセットアップオーディオセッション") \t \t} – user1079052

関連する問題