简体   繁体   English

如何捕获iOS 10上触发/解除的系统警报事件

[英]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 ,例如iMessagePush 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.

相关问题 iOS键盘未关闭 - iOS Keyboards are not being dismissed 如何在系统级别捕获和记录iOS Touch事件? - How to capture and record iOS Touch Events at system level? iOS:点击事件不会仅在 iOS 13 上触发 - iOS: Click events not being triggered only on iOS 13 iOS Swift - 如何在应用程序中检测系统警报 - iOS Swift - How to detect system Alarm in app Xamarin.iOS音频流不起作用,未触发事件 - Xamarin.iOS audio streaming not working, events not being triggered Hammer.js滑动在Safari iOS上未触发的事件 - Hammer.js swipe events not being triggered on Safari iOS 如何捕获iOS中的所有触摸事件? - How to capture ALL touch events in iOS? Swift iOS-在ViewWIllAppear中,如何检查在切换选项卡或打开/关闭视图时是否显示或关闭了ImagePicker? - Swift iOS -In ViewWIllAppear How to Check If ImagePicker is Being Presented or Dismissed While Switching Tabs or The View Is Being Pushed On/Off? 如何在推送通知触发的情况下在后台捕获iOS位置? - How do I capture iOS location in the background, triggered by a push notification? 如何仅使用iOS 10在iOS Swift 3.0中捕获崩溃 - How to capture crashes in iOS Swift 3.0 using only iOS 10
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM