Is there an NSNotification for phone call status

最后都变了- 提交于 2019-12-09 01:00:05

问题


Is there an NSNotification we can observe for when the device is on/off the phone?


回答1:


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.

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).




回答2:


There isn't one that I'm aware of, but if the issue is that you want to know about the change in status bar then you can observe UIApplicationWillChangeStatusBarFrameNotification (as documented towards the bottom of the UIApplication documentation) and get a new rect from the relevant userInfo whenever a change occurs.



来源:https://stackoverflow.com/questions/6604459/is-there-an-nsnotification-for-phone-call-status

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!