我们可以在iphone上有来电和拨出电话时发起一个事件吗? [英] Can we fire an event when ever there is Incoming and Outgoing call in iphone?

查看:170
本文介绍了我们可以在iphone上有来电和拨出电话时发起一个事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在iphone上有来电和外拨通话?

解决方案

是的,可以但不一定立即。



有一个框架,称为CoreTelephony框架,它具有一个 CTCallCenter 类。这个类的一个属性是 callEventHandler 属性。当电话呼叫状态更改时,这是一个被触发的块。例如:

  CTCallCenter * callCenter = ...; //以某种方式获取CallCenter最有可能作为一个全球对象或类似的东西? 

[callCenter setCallEventHandler:^(CTCall * call){
if([[call callState] isEqual:CTCallStateConnected]){
//此调用刚刚连接
} else if([[call callState] isEqual:CTCallStateDisconnected)){
//这个调用刚刚结束(挂起/挂起/ etc)
}
}];

这是真正的,你可以用这个做什么。您无法访问任何电话号码。唯一其他有用的信息是在 CTCall 上的标识符属性,因此您可以唯一标识一个 CTCall 对象。



注意



这个事件处理程序是调用,除非你的应用程序在前台!如果您在应用程序背景时拨打和接听电话,则事件处理程序将不会触发,直到您的应用程序再次活动,此时(根据上述链接的文档),事件处理程序将被调用一次在应用程序处于后台状态时,每个调用已更改状态。


Can I fire an event when ever there is Incoming and Outgoing call ends on iphone? Axample of an event is calling a webservice .

解决方案

Yes you can, but not necessarily immediately.

There is a framework, called the CoreTelephony framework, which has a CTCallCenter class. One of the properties on this class is the callEventHandler property. This is a block that gets fired when then state of a phone call changes. For example:

CTCallCenter *callCenter = ...; // get a CallCenter somehow; most likely as a global object or something similar?

[callCenter setCallEventHandler:^(CTCall *call) {
  if ([[call callState] isEqual:CTCallStateConnected]) {
    //this call has just connected
  } else if ([[call callState] isEqual:CTCallStateDisconnected]) {
    //this call has just ended (dropped/hung up/etc)
  }
}];

That's really about all you can do with this. You don't get access to any phone numbers. The only other useful tidbit of information is an identifier property on CTCall so you uniquely identify a CTCall object.

CAUTION:

This event handler is not invoked unless your app is in the foreground! If you make and receive calls while the app is backgrounded, the event handler will not fire until your app becomes active again, at which point (according to the documentation linked to above) the event handler will get invoked once for each call that has changed state while the app was in the background.

这篇关于我们可以在iphone上有来电和拨出电话时发起一个事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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