Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an iOS VoIP app obey Do Not Disturb when ringing?

Tags:

ios

audio

voip

hig

One would think it would be essential for a VoIP app to obey the same rules as the stock phone app but it turns out to be almost impossible to implement ringing correctly. Several things I tried:

  1. Local push notifications with ring sound.

    Good: obeys both Silent and DND modes.

    Bad: the sound can be no longer than 30 seconds, and it only vibrates once when the notification appears. So to achieve the ringing effect the notification has to be re-pushed e.g. every 6 seconds, effectively spamming the notification center. Also push notifications do not sound/vibrate if the app is active so the app has to detect that and ring differently.

  2. AudioServicesPlayAlertSound().

    Good: proper API seemingly designed specifically for this task. Obeys silent mode.

    Bad: completely ignores Do Not Disturb mode, the sound and vibration come right through.

  3. Use AVFoundation to play the ring sound.

    Good the sound plays.

    Bad: does not support vibration, does not support silent/DND modes. Essentially not usable as a ringer.

Is there a better way? Or did Apple completely miss this use case?

like image 304
SnakE Avatar asked Feb 20 '15 14:02

SnakE


People also ask

What is PushKit?

Overview. The PushKit framework supports specialized notifications for updating your watchOS complications, responding to file provider changes, and receiving incoming Voice-over-IP (VoIP) calls. PushKit notifications differ from the ones you handle with the User Notifications framework.

What is VoIP notification iOS?

VoIP notifications are background messages that don't generate alerts or sounds. These notifications are used to wake up apps and pass across information about incoming calls. With VoIP, mobile apps let users send and receive calls on their devices, using the app interface rather than the default phone interface.


1 Answers

As you say in your 3 options, only a UILocalNotification actually obeys silent/DND mode.

The problems with it can be solved.

Spamming the notification center: I think that works quite well. You can cancel your previous notification immediately before you fire off a new one, so there will always be only 1 outstanding notification.

[[UIApplication sharedApplication] cancelAllLocalNotifications];

Vibration problem: You should be able to call this: AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); in the same place where you call your local notification over and over again with a timer until the call ends or the users acknowledges the call. With the VOIP background setting on it should work in the background.

As you stated in option 2 the vibrate will not follow DND mode, but it's just vibration. If you spam the notification center that will vibrate once every time the notification comes in so you may not need to explicitly start vibrating if that's enough for you.

Good luck.

like image 140
teradyl Avatar answered Oct 17 '22 01:10

teradyl