मेरे ऐप में मैं AVAudio PortTypes को पहले से ही फोन से कनेक्ट करना चाहता हूं। नीचे दिया गया कोड ब्लूटूथए 2 डीडी और हेडफ़ोन के लिए काम करता है, लेकिन जब मैं फोन को अपनी कार हैंड्सफ्री से कनेक्ट करता हूं तो ब्लूटूथ एचएफपी नहीं। क्या कोई मेरी मदद कर सकता है?! मुझे लगता है कि हैंड्सफ्री/एवी/ब्लूटूथ, और कई अन्य सभी एसओ पदों के माध्यम से किया गया है, लेकिन यह काम नहीं कर सकता है कि यह ब्लूटूथ एचएफपी आउटपुट पोर्ट टाइप को क्यों पहचान नहीं रहा है।ऐप AVAudio ब्लूटूथ एचएफपी हैंड्सफ्री पोर्ट स्विफ्ट
import AVFoundation
func startCheckAVConnection() {
// set the AVAudioSession to allow bluetooth. This do/try/catch doesn't seem to make a difference if it is here or not.
do{
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, with: AVAudioSessionCategoryOptions.allowBluetooth)
} catch{
print(error)
}
// Check possible outputs for handsfree
let outputs = AVAudioSession.sharedInstance().currentRoute.outputs
if outputs.count != 0 {
for output in outputs {
if output.portType == AVAudioSessionPortBluetoothA2DP {
peripheralLabel.text = "connected to BluetoothA2DP"
} else if output.portType == AVAudioSessionPortBluetoothHFP { // NOT RECOGNISED
peripheralLabel.text = "connected to BluetoothHFP"
} else if output.portType == AVAudioSessionPortHeadphones {
peripheralLabel.text = "connected to Headphones"
}
}
} else {
peripheralLabel.text = "Please connect handsfree"
}
// Add observer for audioRouteChangeListener
NotificationCenter.default.addObserver(
self,
selector: #selector(TopVC.audioRouteChangeListener(_:)),
name: NSNotification.Name.AVAudioSessionRouteChange,
object: nil)
}
आपको उस मामले में 'output.portType' के लिए क्या मूल्य मिलता है? आपके पास कितने आउटपुट हैं? क्या यह हो सकता है कि आपके पास विभिन्न हैं, और 'peripheralLabel.text' किसी अन्य मान के साथ ओवरराइट हो जाएं? – Larme
हाय लार्मे, केवल एक ही है .portType जब यह A2DP या हेडफ़ोन उठाता है, लेकिन यह ब्लूटूथ एचएफपी को कभी नहीं चुनता है। कोई और विचार? – richc