在iOS 10中获取电话状态 [英] get phone call states in iOS 10

查看:249
本文介绍了在iOS 10中获取电话状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在我的应用中获得电话状态。

经过一些搜索,我找到了 CoreTelephony 框架。但是在iOS 10中已经弃用了。那么还有其他可用的选择吗?
b
我还找到了 CallKit 。 iOS 10中的一个新框架。但没有得到与我搜索相同的调用状态。

I want to get phone call states in my app.
After some search I found CoreTelephony framework. But that is deprecated in iOS 10. SO is there any other alternative available?
I also found CallKit. A new framework in iOS 10. But didn't getting call states from same as I searched.

推荐答案

将CallKit 导入 AppDelegate 并添加以下代码:

import CallKit into your AppDelegate and add the following code:

// AppDelegate
var callObserver: CXCallObserver! // add property

// in applicationDidFinishLaunching...
callObserver = CXCallObserver()
callObserver.setDelegate(self, queue: nil) // nil queue means main thread

extension AppDelegate: CXCallObserverDelegate {
    func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {
        if call.hasEnded == true {
            print("Disconnected")
        }
        if call.isOutgoing == true && call.hasConnected == false {
            print("Dialing")
        }
        if call.isOutgoing == false && call.hasConnected == false && call.hasEnded == false {
            print("Incoming")
        }

        if call.hasConnected == true && call.hasEnded == false {
            print("Connected")
        }
    }
}

这篇关于在iOS 10中获取电话状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆