0

Hi this might be duplicate to this question. But I did not find right answer for this. I have developed an app like zello push to talk using react-native. I want to play the audio message automatically without any user interaction when the app is in background or killed. Whenever any user sending real time audio message, I am sending a push notification to ios app and after receiving notification I am invoking a function which establishes socket connection with the webrtc server and then join in the room in which webrtc audio broadcasting is happening. Now I checked that socket is connected and also joining in room successfully done after receiving push notification when app is in background. But there I could not hear any audio and received following error message.

AURemoteIO.cpp:1668  AUIOClient_StartIO failed (561145187)

Then I have set AVAudioSessionCategoryPlayback and that error gone. But this time also did not hear any audio sound. The app is working fine when it is in foreground. I am using react-native and this is happening for IOS app only. Any help is appreciated. In xcode I have enabled push-notifications, background-fetch, background-airplay etc.

M. Paul
  • 361
  • 5
  • 18

1 Answers1

0

You need to set your app Capabilities Background Modes (Audio and AirPlay).

To Enable this select your iOS project in iOS then go to Signing & Capabilities tab.

Check for Background Modes and select Audio, AirPlay and Picture In Picture option. Also, set your AVAudioSession category to AVAudioSessionCategoryPlayback and set it active. Example:

do {
      try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, options: AVAudioSession.CategoryOptions.mixWithOthers)
      NSLog("Playback OK")
      try AVAudioSession.sharedInstance().setActive(true)
       NSLog("Session is Active")
     } catch {
       NSLog("ERROR: CANNOT PLAY MUSIC IN BACKGROUND. Message from code: \"\(error)\"")
  }
Daljeet
  • 1,573
  • 2
  • 20
  • 40
  • Daljeet as I mentioned in the question that I have already applied Audio, AirPlay and Picture in Picture at Background Modes and set the AVAudioSession to Playback. That time the above error is solved but I still could not hear any voice. – M. Paul Jan 05 '23 at 12:33
  • Did you also added this AVAudioSession.sharedInstance().setActive(true) while setting playback – Daljeet Jan 06 '23 at 05:01
  • Yes I have set that to true. AVAudioSession.sharedInstance().setActive(true) – M. Paul Jan 06 '23 at 06:28