Issue with Twilio Call from URL in WebView on MacOS Catalyst

81 Views Asked by At

Hello Stack Overflow community,

I'm currently facing a challenge with Twilio call functionality in a WebView on MacOS Catalyst. The issue is specific to Twilio calls initiated from a URL within the WebView. Strangely, the functionality works flawlessly in the iPhone simulator, but on MacOS Catalyst, the calls from URL seem to be encountering problems.

@IBOutlet var WKWebView: WKWebView!

override func viewDidLoad() {
    super.viewDidLoad()
    

    permissionForRecording()
    
    // Do any additional setup after loading the view.
}


func permissionForRecording() {
    let session = AVAudioSession.sharedInstance()
    do {
        try session.setCategory(.playAndRecord, mode: .default)
        try session.setActive(true)

        if session.responds(to: #selector(AVAudioSession.requestRecordPermission(_:))) {
            try AVAudioSession.sharedInstance().requestRecordPermission { [weak self] (granted: Bool) -> Void in
                guard let self = self else { return }
                if granted {
                    print("granted")
                    DispatchQueue.main.async {
                        self.setupWKWebView()
                    }
                } else {
                    print("not granted")
                    // Handle case when permission is not granted
                }
            }
        }
    } catch {
        print("Error setting up AVAudioSession: \(error.localizedDescription)")
    }
}

func setupWKWebView() {
    let webConfiguration = WKWebViewConfiguration()
    let preferences = WKWebpagePreferences()
    preferences.allowsContentJavaScript = true // Enable JavaScript
    webConfiguration.defaultWebpagePreferences = preferences

    // Use the existing WKWebView outlet
    WKWebView.isOpaque = false
    WKWebView.navigationDelegate = self
    WKWebView.allowsBackForwardNavigationGestures = true

    let url = URL(string: "")
    let requestObj = URLRequest(url: url!)
    WKWebView.load(requestObj)
}
0

There are 0 best solutions below