gpt4 book ai didi

ios - 使用 CallKit 接听电话时如何显示 ViewController

转载 作者:搜寻专家 更新时间:2023-10-31 19:36:52 26 4
gpt4 key购买 nike

我已按照以下教程在我的应用程序中实现 CallKit:

https://www.raywenderlich.com/150015/callkit-tutorial-ios

但我想更进一步,在调用处于事件状态时显示我自己的 ViewController。我正在做视频通话服务,所以我想有自己的界面。

这可能吗?我一直在尝试从方法 provider(CXProvider:CXAnswerCallAction) 启动 ViewController,这是在用户接听电话时调用的方法,但它似乎每次都崩溃。我正在尝试用这个(Swift 3)实例化它:

let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "VideoCallViewController") as! VideoCallViewController
UIApplication.shared.keyWindow?.rootViewController?.present(vc, animated: true, completion: nil)

它在没有解释的情况下在第二行崩溃。它显示 lldb,我试图通过输入 bt 获取回溯,但它没有返回任何内容。

最佳答案

我想通了:

let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = mainStoryboard.instantiateViewController(withIdentifier: "VideoCallViewController") as! VideoCallViewController

然后,要么:

vc.view.frame = UIScreen.main.bounds
UIView.transition(with: self.window!, duration: 0.5, options: .transitionCrossDissolve, animations: {
self.window!.rootViewController = vc
}, completion: nil)

或:

self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()

根据 https://stackoverflow.com/a/35226874/5798668 ,第一个选项更可取,因为如果您使用第二个选项,您的应用程序中将同时激活多个 UIWindows。

注意:在我的例子中,ProviderDelegate 没有 self.window 属性,这是由 AppDelegate.swift 传递给它的,其中推送通知正在执行委托(delegate)的 reportIncomingCall()

关于ios - 使用 CallKit 接听电话时如何显示 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44590971/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com