AVAudioSession setCategory Swift 4.2 iOS 12 - Play Sound on Silent

前端 未结 9 1948
醉酒成梦
醉酒成梦 2020-12-13 06:06

To play sound even on Silent mode I use to use below method. But how it\'s not working.

// Works on Swift 3  
do {
    try AVAudioSession.sharedInstance().se         


        
9条回答
  •  春和景丽
    2020-12-13 06:20

    The above answer (by Rhythmic Fistman) is correct if your app is not compatible with iOS 9 or below.

    If your app is compatible with iOS 9 you will see the next error:

    'setCategory' is unavailable in Swift

    In that case there is a bug with Swift 4.2, this is an issue with AVFoundation in Xcode 10's SDKs, you can work around it by writing an Objective-C function that calls through to the old API, since they're still available in Objective-C.

    In the next link you can read more details:

    https://forums.swift.org/t/using-methods-marked-unavailable-in-swift-4-2/14949

提交回复
热议问题