在 AVAudioSession 中使用 != buk。 swift 2 中的当前路线
Using != buk in AVAudioSession. currentroute in swift 2
我收到错误二元运算符 '!=' 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")
}
currentRoute
和 outputs
都是非空的。你可以简单地做
for output in currentRoute.outputs {
仅此而已。
我收到错误二元运算符 '!=' 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")
}
currentRoute
和 outputs
都是非空的。你可以简单地做
for output in currentRoute.outputs {
仅此而已。