ios - 如何在使用 Callkit 接听电话后保留 native UI

标签 ios swift voip linphone callkit

我正在使用 Callkit 和 Linphone 开发一个 iOS 网络电话应用程序。当我接到来电时,系统会向用户显示 native 电话 UI 以接受或拒绝通话,当用户点击接受按钮时,通话开始但电话 UI 消失。

如何在用户接听电话后保留原生手机用户界面,就像 whatsapp 一样?

另外,如何在开始拨出电话时显示 native 电话 UI?

这是我的 providerDelegate 代码:

func reportIncomingCall(uuid: UUID, handle: String, hasVideo: Bool = false, completion: ((NSError?) -> Void)? = nil) {
    // Construct a CXCallUpdate describing the incoming call, including     the caller.
    let update = CXCallUpdate()
    update.remoteHandle = CXHandle(type: .generic, value: handle)
    update.hasVideo = hasVideo

    // Report the incoming call to the system
    provider.reportNewIncomingCall(with: uuid, update: update) { error in
        /*
         Only add incoming call to the app's list of calls if the call was allowed (i.e. there was no error)
         since calls may be "denied" for various legitimate reasons. See CXErrorCodeIncomingCallError.
         */
        if error == nil {
            print("calling")

        }
    }
}

func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
    let update = CXCallUpdate()
    update.remoteHandle = action.handle

    provider.reportOutgoingCall(with: action.uuid, startedConnectingAt: Date())
    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "callStart"), object: self, userInfo: ["uuid":action.uuid])
    action.fulfill(withDateStarted: Date())

}

func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "callStart"), object: self, userInfo: ["uuid":action.uuid])

    // ACCEPT CALL ON SIP MANAGER
    if let voiceCallManager = AppDelegate.voiceCallManager {
        voiceCallManager.acceptCall()
    }

    action.fulfill(withDateConnected: Date())

}

最佳答案

接听来电后无法保留原生UI。 Whatsapp 使用自己的 UI,类似于原生 UI。

当您锁定 iPhone 并接听来电时,它不会向您显示 APP UI。但是,如果 iPhone 已解锁并且您接听来电,iPhone 将打开您的应用程序,您必须显示您的手机用户界面。

对于拨出电话,您无法显示 native 电话 UI,如果您接到电话,它会显示。

因此,您需要一个自定义电话 UI 来拨出和建立电话。

关于ios - 如何在使用 Callkit 接听电话后保留 native UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42583903/

相关文章:

ios - 将 dSYM 上传到 crashlytics 时出现问题

ios - UILocalNotification 文本显示在通知中心后如何更改?

用于测试调用的 Linux Asterisk 脚本

cocoa-touch - 可以在 VOIP 应用程序中将多个 tcp 套接字标记为 kCFStreamNetworkServiceTypeVoIP 吗?

ios - 改变 CCSprite 的图像会改变它的大小吗?

objective-c - 如何播放多个音频文件?

ios - 如何使用 iOS 用户代理字符串确定 iOS 版本?

ios - 文本不会包含在 swift UI 中

swift - 为什么在传递给具有可选类型的函数参数时强制使用 nil 的 uwrapped 类型不会崩溃?

swift - 如何在 Swift 3 for Linux 中使用 Process()?