[英]How to capture the events of system alarm being triggered/dismissed on iOS 10
This is my scenario: I have a video player playing some video/audio and suddenly the alarm is called since I set it earlier. 这是我的场景:我有一个视频播放器播放一些视频/音频,然后突然发出警报,因为我之前设置了它。
Before iOS 10
, the alarm's UI and audio would block the main UI thread so the alarm event can be captured by observe the UIWindowDidResignKeyNotification
. 在
iOS 10
之前,警报的UI和音频将阻止主UI线程,因此可以通过观察UIWindowDidResignKeyNotification
来捕获警报事件。
But on iOS 10
, it seems that alarm UI behaves like Notification messages
and will not block the main UI. 但是在
iOS 10
,似乎警报UI的行为类似于Notification messages
并且不会阻止主UI。
But its alarm sound would take over audio thread, so the result is that the video picture is playing while the video sound is not, instead the alarm sound is playing. 但它的警报声会接管音频线程,因此结果是视频图像正在播放而视频声音没有播放,而是播放了警报声。
With iOS 10
what I have done is I observe AVAudioSessionInterruptionNotification
, which would be posted when alarm is running, and once I get it I pause my video playing. 在
iOS 10
,我所做的是观察AVAudioSessionInterruptionNotification
,它将在警报运行时发布,一旦我得到它,我就暂停播放视频。
But this results another issue, which is that my users have to click the play
button manually again after they dismiss the alarm, this is not so good. 但这导致了另一个问题,即我的用户必须在他们解除警报后再次手动点击
play
按钮,这不太好。
Plus AVAudioSessionInterruptionNotification
would be posted when any other type of system audio is triggered, such as iMessage
, Push Notification
which are messages with very short audio, and that causing pauses would really gets users into trouble. 当触发任何其他类型的系统音频时,会发布
AVAudioSessionInterruptionNotification
,例如iMessage
, Push Notification
,它们是音频非常短的消息,并且导致暂停会让用户遇到麻烦。
So I would like to know if there is a way to listen the events that users dismiss the alarm UI up/down. 所以我想知道是否有一种方法来监听用户关闭/关闭警报UI的事件。
Or if anyone could come up with some other solution to solve this kind of problem. 或者,如果有人能提出一些其他解决方案来解决这类问题。
UPDATE: 更新:
This alarm sound takes over the audio thread
issue would only happen when video is decoded by hardware. 此
alarm sound takes over the audio thread
问题仅在视频由硬件解码时发生。
If it's default system decoding for video then it'll be fine. 如果它是视频的默认系统解码,那么它会没问题。
And if incoming call is triggered and call sound also would take over the audio thread which is fine, since incoming call would block the main UI so I can also manage it by observing UIWindowDidResignKeyNotification
. 如果来电被触发并且通话声音也将接管音频线程,这很好,因为来电将阻止主UI,所以我也可以通过观察
UIWindowDidResignKeyNotification
来管理它。
Ok, my fault that I didn't read through apple doc, everything is here . 好吧,我的错,我没有读过苹果文档,一切都在这里 。
You can use the userInfo in AVAudioSessionInterruptionNotification
. 您可以在
AVAudioSessionInterruptionNotification
使用userInfo。
It gives the enums that when it has began, when it ended and even when it's the best time to resume. 它给出了它开始时,它何时结束,甚至是恢复的最佳时间的枚举。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.