2017-06-16 45 views
2
通話

我按照下面的教程,以我的應用程序中實現CallKit當一個視圖控制器:如何顯示回答與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來獲得回溯,但它不返回任何內容。

回答

0

我想通了:

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,其中推送通知正在執行委託的reportIncomingCall()傳遞給它。