iphone applicationWillResignActive - 获取原因
我想知道是否有办法获取 applicationWillResignActive 被调用的原因?
我正在开发一个音频应用程序,我想在屏幕自动锁定时继续录制声音,但我想在来电时停止录制。我怎样才能做到这一点?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需使用 AVAudioSessionDelegate协议方法,例如:
beginInterruption
和/或endInterruptionWithFlags:
来检查是否录音被中断,您可以做任何您需要的事情。在这种情况下,这种方法比注册电话事件更有优势,因为它可以一直进行录音,而不仅仅是前 10 分钟。
You can simply use the AVAudioSessionDelegate protocol methods like:
beginInterruption
and/orendInterruptionWithFlags:
to check if the recording is interrupted and than you can do whatever you need.In this case this approach has an advantage over registering to telephony events, because it works all the time recording, and not only for the first 10 minutes.
您可以参考 核心电话框架。该框架使您可以在设备上监听手机的事件和状态。
此外,
CTCallCenter
类使您可以注册电话事件,以便通过您的应用程序正确处理它们。这样,您就可以在来电到达、呼叫开始、终止等时调用特定的回调。请参阅 蜂窝呼叫状态的完整列表。希望这有帮助。
You can refer to the Core Telephony Framework in your application. This framework gives you the possibility of listening to the events and state of the phone on your device.
Moreover, the
CTCallCenter
class gives you the possibility of registering to telephony events to appropriately handle them through your application. This way you will be able to call a specific callback when an incoming call arrives, a call is started, terminated and so on. See the full list of cellular call states.Hope this helps.