iOS AVAudioSessionInterruptionNotification通知接收混乱

iOS AVAudioSessionInterruptionNotification通知接收混乱

问题:进入前台收到音频打断通知

处理AVAudioSessionInterruptionNotification通知时,每次退到后台,然后退到前台,会受到一个AVAudioSessionInterruptionNotification通知,且AVAudioSessionInterruptionTypeKey
为AVAudioSessionInterruptionTypeBegan,表示很诧异,我并没有音频打断啊,没有电话call进来。后面查了官方文档说明:https://developer.apple.com/documentation/avfoundation/avaudiosessioninterruptionnotification

If your audio session is configured to be non-mixable (the default behavior for the AVAudioSessionCategoryPlayback, AVAudioSessionCategoryPlayAndRecord, AVAudioSessionCategorySoloAmbient, and AVAudioSessionCategoryMultiRoute categories), it's recommended that you deactivate your audio session if you're not actively using audio when you go into the background. Doing so will avoid having your audio session deactivated by the system (and receiving this somewhat confusing notification).

Note

Starting in iOS 10, the system will deactivate the audio session of most apps in response to the app process being suspended. When the app starts running again, it will receive an interruption notification that its audio session has been deactivated by the system. This notification is necessarily delayed in time because it can only be delivered once the app is running again. If your app’s audio session was suspended for this reason, the userInfo dictionary will contain the AVAudioSessionInterruptionWasSuspendedKey key with a value of YES.

If your audio session is configured to be non-mixable (the default behavior for the AVAudioSessionCategoryPlayback, AVAudioSessionCategoryPlayAndRecord, AVAudioSessionCategorySoloAmbient, and AVAudioSessionCategoryMultiRoute categories), it’s recommended that you deactivate your audio session if you’re not actively using audio when you go into the background. Doing so will avoid having your audio session deactivated by the system (and receiving this somewhat confusing notification).

从ios10开始,系统将关闭大多数应用程序的音频会话,以响应应用程序进程被暂停。当应用程序重新开始运行时,它将收到一个中断通知,提示它的音频会话已被系统停用。这个通知必然会延迟,因为它只能在应用程序再次运行时发送。如果您的应用程序的音频会话因此暂停,userInfo字典将包含AVAudioSessionInterruptionWasSuspendedKey值为YES的键。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值