How to check if Airpods are connected to iPhone programatically?

I am trying to check if AirPods are connected to the iPhone. How can I check it programmatically?

For airpods port.portType value is .builtInMic which is not sufficient to check if airpods are connected to iphone

class func isMicAvailbale() -> Bool{ let availableInputs:[AVAudioSessionPortDescription] = AVAudioSession.sharedInstance().availableInputs ?? [] var micPresent = false; for port in availableInputs { if port.portType == .builtInMic{ micPresent = true } } return micPresent }