是否有NSNotification的电话呼叫状态 [英] Is there an NSNotification for phone call status
问题描述
当设备打开/关闭手机时,我们可以观察到NSNotification吗?
Is there an NSNotification we can observe for when the device is on/off the phone?
推荐答案
NotificationCenter
不会发出任何通知,但是看看iOS 4中引入的 CTCallCenter
类。它有一个 callEventHandler
属性,你可以分配一个块代码,并通过调用状态信息调用。
The NotificationCenter
doesn't send out any notifications abou this, but take a look at the CTCallCenter
class introduced in iOS 4. It has a callEventHandler
property that you can assign a block of code to, and gets called with call state info.
有一个限制,只有当你的应用程序在前台(或被取出)时才会调用处理程序来电时的前景),但它会告诉您用户是否正在拨号( CTCallStateDialing
),接听电话( CTCallStateIncoming
),回答/连接( CTCallStateConnecting
)或挂断电话( CTCallStateDisconnected
)。
There is a limitation in that the handler only gets called when your app is in the foreground (or being taken out of the foreground when a call comes in), but it tells you if the user is dialing (CTCallStateDialing
), receiving a call (CTCallStateIncoming
), answering/connecting (CTCallStateConnecting
) or hanging up on a call (CTCallStateDisconnected
).
这篇关于是否有NSNotification的电话呼叫状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!