gpt4 book ai didi

ios - 在 AVAudioSession 中使用 != buk。 swift 2 中的当前路线

转载 作者:搜寻专家 更新时间:2023-11-01 07:30:19 26 4
gpt4 key购买 nike

我收到错误 Binary operator '!=' cannot be applied to operands of type '[AVAudioSessionPortDescription]' and 'NilLiteralConvertible in Swift 2,这在 Swift 1 之前很好程序检查耳机线是否插入

var currentRoute = AVAudioSession.sharedInstance().currentRoute 

if currentRoute.outputs != nil {

for description in currentRoute.outputs {
if description.portType ==

AVAudioSessionPortHeadphones {
print("headphone plugged in")
auximage.image=on

} else {
print("headphone pulled out")

auximage.image=off
}
}
} else {
print("requires connection to device")
}

最佳答案

currentRouteoutputs 都是非空的。你可以简单地做

for output in currentRoute.outputs {

仅此而已。

关于ios - 在 AVAudioSession 中使用 != buk。 swift 2 中的当前路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32902469/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com