我一直在尝试为我的应用实现VOIP,而我希望实现的一项功能是将视图自动更改为“呼叫视图”(CallViewController),在此情况下,用户可以接受或拒绝呼叫来自应用程序中任何位置的来电。我的应用程序将处于信息亭模式,因此我不需要推送通知。目前,用户可以在应用程序中的每个位置接收呼叫,但用户必须手动转到呼叫视图。我相信可以做到,因为当有来电时,提供的代码会自动从“选择要呼叫的人(MainViewController)”页面切换到“呼叫”页面(呼叫视图)。我希望可以在整个应用范围内实施。谢谢你的帮助!
以下是“选择呼叫者”页面的代码:
class MainViewController: UIViewController, UITextViewDelegate, SINCallClientDelegate {
override func viewDidLoad() {
super.viewDidLoad()
}
func client() -> SINClient {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
return appDelegate.client!
}
@IBAction func call(_ sender: AnyObject) {
if !destination.text!.isEmpty && client().isStarted() {
let call: SINCall = client().call().callUser(withId: destination.text)
performSegue(withIdentifier: "callView", sender: call);
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any!) {
let callViewController: CallViewController
if segue.identifier == "callView" {
callViewController = segue.destination as! CallViewController
let call = sender as! SINCall
callViewController.call = call
call.delegate = callViewController
} else if segue.identifier == "returnMainPage" {
shouldPerformSegue(withIdentifier: "returnMainPage", sender: Any?.self)
}
}
override func awakeFromNib() {
client().call().delegate = self
}
func client(_ client: SINCallClient!, didReceiveIncomingCall call: SINCall!) {
performSegue(withIdentifier: "callView", sender: call)
}
func client(_ client: SINCallClient!, localNotificationForIncomingCall call: SINCall!) -> SINLocalNotification! {
let ret = SINLocalNotification()
ret.alertAction = "Answer"
ret.alertBody = "Incoming call from " + call.remoteUserId
return ret;
}
答案 0 :(得分:0)
确实收到的呼入应该作为单例对象或在appdelegate中实现。然后您可以启动任何控制器。