Notification with sound in Swift

1

I have a problem making an application similar to an alarm. It turns out that I can not find any way for the user to select a song in their library and use it when they touch a notification. Is that possible in Swift?

What I implemented was an excerpt that carries an internal sound file, but I would like to take a song from the library:

let content = UNMutableNotificationContent()
content.title = "Late wake up call"
content.body = "The early bird catches the worm, but the second mouse gets the cheese."
content.categoryIdentifier = "alarm" 

content.sound = UNNotificationSound.init(named: "my-music.mp3");

Another issue is that I did not find anything related to the iOS alarm, in that it opens a screen with a STOP or ADVANCE button even in the background. In Swift, is it possible?

    
asked by anonymous 16.07.2017 / 18:59

1 answer

0

Notification sounds (local or remote) are meant to be an alert, so you have restrictions:

  • Audio file in aiff, wav, or caf (in Linear PCM, MA4 (IMA / ADPCM) encodings, μLaw or aLaw);
  • Being in the application's Bundle or in the Library / Sounds folder of the container;
  • Having less than 30 seconds;

Documentation: Local and Remote Notification Programming Guide

On the iOS alarm, there is still no possibility to display content on the locked screen as Apple does.

All the alarm apps I tried do not let iOS crash, just turn off the screen. If you want to follow this path, take a look at the properties:

  • UIApplication > isIdleTimerDisabled ;
  • UIDevice > proximityMonitoringEnabled ;
17.07.2017 / 22:24