How do I fill in CXProviderDelegate in SwiftUI?

I'm working on porting the source of an app I took from a sample to an app I created by myself by changing it to SwiftUI. I don't know how to port the following CXProviderDelegate.

If I port it as is If I port it as-is, I get an error saying that the non-class type 'VideoView' cannot conform to class protocol 'CXProviderDelegate'.

Please let me know how to port it.

extension videoTabView: CXProviderDelegate { func providerDidReset(_ provider: CXProvider) {

}

func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
    callCenter.ConfigureAudioSession()
    callCenter.Connecting()
    action.fulfill()
}

func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
    callCenter.ConfigureAudioSession()
    if let peer = self.dataConnection?.peer {
        self.call(targetPeerId: peer)
    }
    action.fulfill()
}

func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
    self.dataConnection?.close()
    self.mediaConnection?.close()
    action.fulfill()
}

}

Answered by OOPer in 697651022

As you found, you cannot make a view type (which is a struct!) conform to CXProviderDelegate.

You need to create a class inheriting NSObject and make it conform to CXProviderDelegate and use it in your view.


By the way, in Swift, type names should start with Capital letters. You should not use videoTabView as a View name.

Accepted Answer

As you found, you cannot make a view type (which is a struct!) conform to CXProviderDelegate.

You need to create a class inheriting NSObject and make it conform to CXProviderDelegate and use it in your view.


By the way, in Swift, type names should start with Capital letters. You should not use videoTabView as a View name.

As @OOPer says, a CXProviderDelegate must be an NSObject, so it can't be a SwiftUI View.

It would have to be a class, perhaps as (part of) your Model or ViewModel (assuming that you are using MVVM).

Remember that SwiftUI is only providing the user interface for your app.
SwiftUI is not doing all the behind-the-scenes processing!

Thank you very much. It worked fine.

The only thing is that func provider(_ provider: CXProvider, perform action: CXAnswerCallAction)

How can I transition the View after confirming an incoming call?

How do I fill in CXProviderDelegate in SwiftUI?
 
 
Q