简体   繁体   中英

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 .

But on iOS 10 , it seems that alarm UI behaves like Notification messages and will not block the main 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.

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.

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.

So I would like to know if there is a way to listen the events that users dismiss the alarm UI up/down.

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.

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 .

Ok, my fault that I didn't read through apple doc, everything is here .

You can use the userInfo in AVAudioSessionInterruptionNotification .

It gives the enums that when it has began, when it ended and even when it's the best time to resume.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM