Audio not working when incoming call is answered during screen is locked - swift

Visal Sambo

I am buidling an app using VOIP service. Now i integrated my app with CallKit in order to handle incoming call request.

When the app stays in foreground or background they are working fine when answered call. But the problem is that when the screen is locked and i tried to answer the call but unfortunately I can't hear audio for both side even i unlocked the screen.

How to solve this issue?

This is how incoming call reports:

func reportIncomingCall(uuid: UUID, handle: String, hasVideo: Bool = false, completion: ((NSError?) -> Void)?) {
    // 1.
    print("This is UUID === ", uuid)
    configureAudioSession()
    let update = CXCallUpdate()
    update.remoteHandle = CXHandle(type: .phoneNumber, value: handle)
    update.hasVideo = hasVideo


    provider.reportNewIncomingCall(with: uuid, update: update) { error in


        if error == nil {
            // 3.
            self.configureAudioSession()
            let call = CallKitCallInit(uuid: uuid, handle: handle)
            self.callKitManager.add(call: call)
            lastCallUUID = uuid
            print("UUID === ", uuid)
        } else {

        }

        // 4.
        completion?(error as NSError?)
    }


}

This is how i set audio

func configureAudioSession() {
    let session = AVAudioSession.sharedInstance()
    do{
        try session.setCategory(AVAudioSessionCategoryPlayAndRecord)

    } catch {
        print("========== Error in setting category \(error.localizedDescription)")
    }
    do {
        try session.setMode(AVAudioSessionModeVoiceChat)
    } catch {
        print("========= Error in setting mode \(error.localizedDescription)")
    }
    do {
        try session.setPreferredSampleRate(44100.0)
    } catch {
        print("======== Error setting rate \(error.localizedDescription)")
    }
    do {
        try session.setPreferredIOBufferDuration(0.005)
    } catch {
        print("======== Error IOBufferDuration \(error.localizedDescription)")
    }
    do {
        try session.setActive(true)
    } catch {
        print("========== Error starting session \(error.localizedDescription)")
    }
}

When i answered the call when screen is locked i could see that the error that it throwed in configureAudioSession() function.

Why it not able to set audio when the screen is locked?

Visal Sambo

I did by adding these lines of code

func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
    // 1.
    guard let call = callKitManager.callWithUUID(uuid: action.callUUID) else {
        action.fail()
        return
    }
    // 2.
    configureAudioSession()
    // 3.
    call.answer()
    // 4.
    action.fulfill()
}

This is configureAudioSession

func configureAudioSession() {
    let session = AVAudioSession.sharedInstance()

    do{
        try session.setCategory(AVAudioSession.Category.playAndRecord,
                                mode: AVAudioSession.Mode.voiceChat,
                                 options: [])

    } catch {
        print("========== Error in setting category \(error.localizedDescription)")
    }

    do {
        try session.setPreferredSampleRate(44100.0)
    } catch {
        print("======== Error setting rate \(error.localizedDescription)")
    }
    do {
        try session.setPreferredIOBufferDuration(0.005)
    } catch {
        print("======== Error IOBufferDuration \(error.localizedDescription)")
    }
    do {
        try session.setActive(true)
    } catch {
        print("========== Error starting session \(error.localizedDescription)")
    }
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to redirect already answered incoming call using pjsip?

分類Dev

Why is the gnome keyring not locked when the screen is locked?

分類Dev

How to achieve a "contact" button on incoming call screen

分類Dev

Notification vibration, sound when screen is locked

分類Dev

Get a notification & dialog when the screen is locked

分類Dev

ios NotificationService Extension is not called when screen is locked

分類Dev

ios NotificationService Extension is not called when screen is locked

分類Dev

Get event for incoming call when application in background

分類Dev

componentDidMount is not working when redirect to a screen

分類Dev

Android: C++ thread not waking up if screen-locked or in background. Works fine when app is in use

分類Dev

Black screen when segueing to UITableViewController in swift

分類Dev

PopUp while receiving Incoming Call

分類Dev

How to Intercept incoming call in Mule

分類Dev

Twilio add incoming call to queue and call to the agent

分類Dev

Enable mute button even if screen is locked

分類Dev

Fix Synergy so it works on Login/Locked screen

分類Dev

Enable mute button even if screen is locked

分類Dev

how to show a screen if sony smartwatch is locked

分類Dev

Swift: Call Function when NSTextField is Edited

分類Dev

Call function when Animation finish in Swift

分類Dev

How to answer automatically and programatically an incoming call on android

分類Dev

Get incoming call number programmatically on android 10

分類Dev

Intercept incoming call in a rooted Android (Jelly Bean)

分類Dev

How to read the number of incoming call on Android Device

分類Dev

Windows 8.1 detect incoming phone call

分類Dev

Wrap Text in UITableView Custom Cell When It Reaches End of Screen (Swift)

分類Dev

Skype audio not working in 16.04

分類Dev

How to record desktop screen with audio?

分類Dev

PDFBox encrypted / locked PDF is still modified by Adobe Reader during 'save as'

Related 関連記事

  1. 1

    How to redirect already answered incoming call using pjsip?

  2. 2

    Why is the gnome keyring not locked when the screen is locked?

  3. 3

    How to achieve a "contact" button on incoming call screen

  4. 4

    Notification vibration, sound when screen is locked

  5. 5

    Get a notification & dialog when the screen is locked

  6. 6

    ios NotificationService Extension is not called when screen is locked

  7. 7

    ios NotificationService Extension is not called when screen is locked

  8. 8

    Get event for incoming call when application in background

  9. 9

    componentDidMount is not working when redirect to a screen

  10. 10

    Android: C++ thread not waking up if screen-locked or in background. Works fine when app is in use

  11. 11

    Black screen when segueing to UITableViewController in swift

  12. 12

    PopUp while receiving Incoming Call

  13. 13

    How to Intercept incoming call in Mule

  14. 14

    Twilio add incoming call to queue and call to the agent

  15. 15

    Enable mute button even if screen is locked

  16. 16

    Fix Synergy so it works on Login/Locked screen

  17. 17

    Enable mute button even if screen is locked

  18. 18

    how to show a screen if sony smartwatch is locked

  19. 19

    Swift: Call Function when NSTextField is Edited

  20. 20

    Call function when Animation finish in Swift

  21. 21

    How to answer automatically and programatically an incoming call on android

  22. 22

    Get incoming call number programmatically on android 10

  23. 23

    Intercept incoming call in a rooted Android (Jelly Bean)

  24. 24

    How to read the number of incoming call on Android Device

  25. 25

    Windows 8.1 detect incoming phone call

  26. 26

    Wrap Text in UITableView Custom Cell When It Reaches End of Screen (Swift)

  27. 27

    Skype audio not working in 16.04

  28. 28

    How to record desktop screen with audio?

  29. 29

    PDFBox encrypted / locked PDF is still modified by Adobe Reader during 'save as'

ホットタグ

アーカイブ