头文件:import CoreTelephony声明一个全局的属性:let callCenter = CTCallCenter()//拨号let number = "10086"let callWebVIEw = UIWebVIEw()callWebVIEw.loadRequest(URLRequest(url:URL(string: "tel:\(number)")!))vIEw.addSubvIEw(callWebVIEw)UIApplication.shared.open(URL(string:number)!,options: ["":""],completionHandler: nil)//获取通话状态callCenter.callEventHandler = { (call: CTCall) -> VoID in if call.callState == CTCallStatedisconnected { print("电话挂断") } if call.callState == CTCallStateConnected { print("电话接通") } if call.callState == CTCallStateIncoming { print("通话途中收到别的来电") } if call.callState == CTCallStateDialing { print("电话播出") }}iOS10
头文件:import CallKit.CXCallObserver声明全局属性<必须的,不然代理无法监听>let callObserver = CXCallObserver()//拨号let number = "10086"let callWebVIEw = UIWebVIEw()callWebVIEw.loadRequest(URLRequest(url:URL(string: "tel:\(number)")!))vIEw.addSubvIEw(callWebVIEw)UIApplication.shared.open(URL(string:number)!,options: ["":""],completionHandler: nil)设置代理callObserver.setDelegate(self,queue: dispatchQueue.main)实现代理方法:extension VIEwController: CXCallObserverDelegate { func callObserver(_ callObserver: CXCallObserver,callChanged call: CXCall) { if call.isOutgoing { print("电话播出") if call.hasConnected { print("电话接通") operation(state: CurrentState.HasConnected) } if call.hasEnded { print("电话挂断") operation(state: CurrentState.HasEnded) } if call.isOnHold { print("无人接听挂断") operation(state: CurrentState.IsOnHold) } } else { print("other error") } }}DEMO地址(基于Swift3.0的一个循环拨打电话的小功能的,直到接通为止) 总结
以上是内存溢出为你收集整理的Swift3.0拨打电话,获取通话状态(接通,挂断...)<CoreTelephony,CallKit.CXCallObserver>全部内容,希望文章能够帮你解决Swift3.0拨打电话,获取通话状态(接通,挂断...)<CoreTelephony,CallKit.CXCallObserver>所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)