I want to play the sound in the background

I want to play a sound when the app is go in the background! I am playing the sound using time picker
I am selecting the time from the time picker and hitting the play button then I place the app in the background so sound is not playing but when my app is active then the sound is playing.
I want to play the sound in the background

HI @Amit_Rai

In your AppDelgate willFinishLaunchingWithOption


do {
            try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault, options: [.mixWithOthers, .allowAirPlay])
            print("Playback OK")
            try AVAudioSession.sharedInstance().setActive(true)
            print("Session is Active")
        } catch {
            print(error)
        }
        return true

When calling it, be sure to add:

options: [.allowAirPlay, .defaultToSpeaker]

And also be sure to turn on the options in background modes:
picts

Blessings,
—Mark

2 Likes

Yes it is working fine when the app is active and I play the sound by clicking the play button then I go to home screen it is playing! but when I set the timing and I place the app in the background so the sound is not playing at that time

I have also getting this error in the debug console
**The operation couldn’t be completed. (OSStatus error -50.) *