1

我正在尝试开发一个提供AudioVideo调用的应用程序,现在我正在关注baresip相同的库。

我在按钮 Click 上写了以下代码:

@IBAction func btnCallClick(_ sender: Any) {
    guard libre_init() == 0 else { return }

    // Initialize dynamic modules.
    mod_init()

    // Make configure file.
    if let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first {
        conf_path_set(path)
    }
    guard conf_configure() == 0 else { return }

    // Initialize the SIP stack.
    guard baresip_init(conf_config(), 0) == 0 else { return }
    guard ua_init("SIP", 1, 1, 1, 0) == 0 else { return }

    // Load modules.
    guard conf_modules() == 0 else { return }

    let addr = "sip:101@xxx.xxx.com:port;auth_pass=aaaa;transport=udp;answermode=auto"

    // Start user agent.
    guard ua_alloc(&agent, addr) == 0 else { return }

    // Make an outgoing call.
    guard ua_connect(agent, nil, nil, "sip:100@xxx.xxx.com", VIDMODE_OFF) == 0 else { return }

    // Start the main loop.
    re_main(nil)
}

现在,我从一台设备接到另一台设备的电话,但它挂起我的视图,为什么它是挂起的视图?我花了很多时间,有人可以帮助我吗?

4

1 回答 1

1

我认为真正的问题是你在re_main()函数最后一行的函数。它正在启动线程的循环执行。因此,除非您调用该re_cancel()函数,否则您对进程的执行将保留在线程中。

解决方案: 将您的re_main()功能放在用户启动的全局线程上将解决您的问题。它将在用户启动的全局队列上启动所有另一个进程,并且主线程将免费用于您的 UI 交互目的。

DispatchQueue.global(qos: .userInitiated).async {
        re_main(nil)
}
于 2019-04-30T09:33:57.213 回答