I make an alarm app. This is what my view looks like:

enter image description here

What is already working:

I pressed the "6:00" button with a single tap, my addAlarm("6:00", "unstable") function addAlarm("6:00", "unstable") . Button "6:00" became highlighted in green. The time itself was memorized in the data model of the application so that the button with the corresponding time remains highlighted after closing and re-opening the application.

The “8:00” button is lit in red, because I tapped it twice and the addAlarm("6:00", "stable") function addAlarm("6:00", "stable") worked. Information was also recorded in the data model.

What I want:

The green color of the “6:00” button means that the alarm should work once at 6 am, and then should be deactivated, that is, the button should turn blue again.

The red color of the “8:00” button means that the alarm should work every day at 8 am, but after that the button should also remain red.

By triggering the alarm, I mean the following. A notification with the text “Wake up” appears on the device screen, and the melody starts playing. The file with the melody lasts 20 seconds, but I want the melody to last 3 minutes, constantly repeating the 20 second file with the melody.

The alarm should be triggered even when the application is minimized, the phone is in sleep mode, or set to do not disturb.

What I do not understand:

Well, of course, how to do what I want :–) But seriously, it is not clear to me what methods to use. I managed to find the following.

You can use NSTimer to call some callback after a designated time, but the timers stop working 10 minutes after the application is minimized.

You can and should use UIApplication.sharedApplication (). ScheduleLocalNotification (notification) for a notification to appear, but the accompanying notification melody cannot exceed 30 seconds, nor is it clear to me how to call my removeAlarm(time) function for alarm clocks set once, if the user does will not respond to the notification, for example, will not wake up.

You can use the Background Modes .

In general, the question is:
What or what methods to use, how to combine them, and generally in which direction to drip?

  • How did they get a melody from sleep mode? - xhr
  • I scored on this alarm clock and swift, and generally decided to retrain from the developer to the product manager. Such pies. - iserdmi

1 answer 1

Use

UIApplication.sharedApplication (). ScheduleLocalNotification (notification)

Just alternate it several times in a row, i.e. Put not one notification but a pack in a row. And you can just call the notification with sound, without displaying it on the screen.

Ie the first we can display, and the next just play the sound.