IOS Walkie Talkie application plays audio in the background

I am working on a Walkie Talkie app and support the basics. You select a user, record a message, which is then sent via a push notification. They open an application that downloads and plays the message. I was pleased with this until I came across Zello .

They do two things of interest:

1) If you receive a message and the application is running in the background, it will display a notification and start playing the message without having to open the application.

Zello

2) A message is sent to your phone and starts playback while the other user is still talking.

Can someone let me know how they do it? I added basics such as setting the audio / voip background mode buttons and initializing the audio session:

[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayAndRecord error:nil]; [[AVAudioSession sharedInstance] setActive:YES error:nil]; 

But I'm not sure how to proceed beyond this.

+4
source share
1 answer

Try using this code in viewdidload mode:

  NSError *setCategoryErr = nil; NSError *activationErr = nil; [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryErr]; [[AVAudioSession sharedInstance] setActive: YES error: &activationErr]; [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid; newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL]; 

Hope this helps you.

+1
source

Source: https://habr.com/ru/post/1433192/


All Articles