问题
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