Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom alarm notifications IOS keep application running

I am trying to create an alarm clock app which plays either downloaded or streamed video and audio as a local notification. For Android this is doable but for IOS I know that apple has restrictions.

I have noticed that Rise and The Rock Clock require you to keep the app in the foreground (example below) . I have read that they do this by disabling multitasking UIApplicationExitsOnSuspend.

I am wondering whether this is still the only (best?) way to show custom notifications or whether they are just supporting older operating systems and there is changes in IOS that provide a better user experience?

Thanks

enter image description here

like image 926
Nicholas Muir Avatar asked Nov 05 '17 11:11

Nicholas Muir


2 Answers

There are not so much possible ways to do this and no one is good.

  1. You can schedule UILocalNotification or UNNotificationRequest. This way allow You to create alarm with some predefined sound. Not helpful because of sound duration limit and impossibility to play stream.
  2. URLSession with background configuration. According to documentation You can schedule request. Works only from iOS 11, no guarantee that request will be executed.

  3. Use VoIP or silent push. This types of pushes have possibility to launch app in background when received by device. Tricky way but can do the job. Not helpful if user has no internet connection.

  4. Keep app in foreground. Simplest way and works like a charm. Too heavy for device battery.

UPD: Just to gather all answers in one place (Thanks to @jba).

There is also possibility to use "Audio and Airplay" background category. You can play "silence" or record audio when device is locked. This is very energy consumnable way, also, some of OS interuptions, like phone call, can stop audio playback/record and app can be suspended.

like image 174
HereTrix Avatar answered Sep 19 '22 18:09

HereTrix


Apple won't give you much ways to achieve this, but the few you have are well and quite precisely documented. For your app I would advise to go with the "Audio and Airplay" option as it will allow you to play and/or record audio in the background. Then your hard work is to find the right way to explain why you do this to your users, and what is the benefit for them... At the end this feature would let your app alive all the time until firing the alarm and then play your audio file.

like image 25
JBA Avatar answered Sep 19 '22 18:09

JBA