How do I get the iOS VoIP app to perform Do Not Disturb when making a call?

One might think that for a VoIP application it is important to follow the same rules as a desktop application, but it turned out that it is practically impossible to make a call correctly. A few things I tried:

  • Local push notifications with ringtone.

    Good: obeys Silent and DND.

    Bad: the sound can be no more than 30 seconds, and it only vibrates once when a notification appears. Therefore, to achieve the effect of the call, the notification must be repeatedly pressed, for example. every 6 seconds, effectively sending out a notification center. In addition, push notifications do not sound or vibrate if the application is active, so the application must detect it and ring in a different way.

  • AudioServicesPlayAlertSound() .

    Good: the right API created specifically for this task. Performs silent mode.

    Bad: completely ignores the Do Not Disturb mode, sound and vibration go straight.

  • Use AVFoundation to play a ringtone.

    Good sound is reproduced.

    Bad: does not support vibration, does not support silent / DND modes. Essentially not used as a call.

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

+6
source share
1 answer

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

Problems with it can be solved.

Notification Center Spam: I think this works well. You can cancel your previous notification right before you launch it, so there will always be only one outstanding notification.

[[UIApplication sharedApplication] cancelAllLocalNotifications];

Vibration Problem:. You should be able to call it: AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); in the same place where you call your local notification again and again using the timer until the call ends, or users confirm that the call. With background settings, VOIP on it should work in the background.

As you indicated in option 2, the vibration will not follow the Do Not Disturb mode, but it is just vibration. If you spam a notification center that will vibrate once every time a notification arrives, so you may not need to explicitly trigger a vibration if that's enough for you.

Good luck.

+2
source

Source: https://habr.com/ru/post/982792/


All Articles