【问题标题】:Swift: Twilio delegate functions not being calledSwift:未调用 Twilio 委托函数
【发布时间】:2020-10-18 18:48:40
【问题描述】:

请原谅我的 Swift 菜鸟。

我正在使用 Twilio 的 VideoCall 框架,想知道为什么我的 RoomDelegate 函数没有被调用。

在我看来,我有一个 RoomDelegate 实例

struct AppHome: View {
    var roomDelegate = myRoomDelegate()

当我连接到一个房间时,我传入了我的 roomDelegate:

let connectOptions = ConnectOptions(token: self.accessToken) { (builder) in
    builder.roomName = self.call.call_api.room_name
    builder.audioTracks = [self.roomDelegate.localAudioTrack!]
}
let room = TwilioVideoSDK.connect(options: connectOptions, delegate: self.roomDelegate)

我的 roomDelegate 类有:

class myRoomDelegate: NSObject, RoomDelegate {
    ...
    func roomDidConnect(room: Room) {
        print("Delegate " + #function)
    }
    func roomDidDisconnect(room: Room, error: Error?) {
        print("Delegate " + #function)
    }
    func roomDidFailToConnect(room: Room, error: Error) {
        print("Delegate " + #function)
    }
    func roomIsReconnecting(room: Room, error: Error) {
        print("Delegate " + #function)
    }
    func roomDidReconnect(room: Room) {
        print("Delegate " + #function)
    }
    func participantDidConnect(room: Room, participant: RemoteParticipant) {
        print("Delegate " + #function)
    }
    func participantDidDisconnect(room: Room, participant: RemoteParticipant) {
        print("Delegate " + #function)
    }
}

我发现的所有委托示例都使用self,所以我试图了解我所做的是否有效,如果是,为什么我的委托回调没有受到影响?

【问题讨论】:

    标签: ios swift delegates twilio


    【解决方案1】:

    在我看来你的类型有问题,所以将你的结构更改为 class 并尝试运行:

    class AppHome: View {
        var roomDelegate = myRoomDelegate()
    }
    

    【讨论】:

    • 我不明白会是这样。它构建为一个结构,而不是一个类。但我也看不出这对解决问题有什么帮助。
    猜你喜欢
    • 1970-01-01
    • 2019-09-20
    • 2021-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-07
    • 1970-01-01
    相关资源
    最近更新 更多