How to add live audio to your iOS application with Voxer SDK

How to add live audio to your iOS application with Voxer SDK

Over the past 18 months, nearly every company has had to to deal with the rapid transition to remote work. This has created a wave of increased user needs for both asynchronous and synchronous communication features that offer the connectivity and flexibility needed in todays digital landscape. Integrating live audio communication and other modern messaging tools into your own application is easier than ever with Voxer SDK. Within minutes you can send audio and text messages to a group of users and enable an external Push-to-talk button so that audio messages can be sent any time, and played even when your app is the background.

Using the Voxer SDK, the complexity of adding synchronous and asynchronous communication is dramatically simplified. Here’s how you can add communication features easily to your iOS application.

Requirements

– A Voxer SDK developer account (link to sign up)
– A deployment target of iOS 11
– Xcode 12.5
– CocoaPods

Setup

Let’s start by configuring your Xcode project. Create or start with an already existing iOS project in Xcode and add the VoxerKit.xcramework to your project. Under your project make sure “Embeded & Sign” is selected by going to General ? Targets ? Frameworks, Libraries and Embedded Content. Next, Go to your project “Build Settings” -> “Excluded Architectures” -> Add “Any iOS Simulator SDK” with the value “arm64” (for Debug And Release). Lastly, In “Signing & Capabilities” add “Background Modes” and then select “Audio, AirPlay, and Picture in Picture” and “Voice over IP”.

Once your Xcode project is configured, we can now initialize the Voxer SDK by adding the following snippet:

let voxer: Voxer = Voxer(isBackgroundAudioEnable: true)

Now we can add authentication by logging into the Voxer network with:

voxer.loginWith(username: username, password: password) { [weak self] response in
  if response == .success {
    print ("Login suceeded")
  } else {
    print ("Login failed")
  }
}

You can check if a user is already logged in with the following:

if voxer.loggedInUsername?.isEmpty == false {
  // User already logged from previous session.
}

Now that you have initialized the Voxer SDK and logged into the Voxer network, you can now start a chat with a group of users, send text and audio messages, and enable Walkie-Talkie mode.

Enable External Push-to-talk (PTT) Button 

You can now enable an external PTT button feature called Walkie Talkie Mode that allows allows your app to record and send audio messages any time rather your app is in the foreground or “running” in the background. 

Notes: if your app is suspended in the background, Walkie Talkie mode does not work.

Enable Walkie Talkie

if voxer.enableWalkieTalkie(for: chatId) != true {
    print("ERROR: Could not enable walkie talkie for chat.id: (chatId)")
}

Disable Walkie Talkie

if voxer.disableWalkieTalkie(for: chatId) != true {
    print("ERROR: Could not disable walkie talkie for chat.id: (chatId)")
}

Get Current Walkie Talkie Chat

let chatId = voxer.getWalkieTalkieChatId()

Talk with Walkie Talkie Mode

The first call to this method starts recording the audio and sends it. The second call to this method will stop the audio recording.

let toggleSuccess = voxer.toggleWalkieTalkie { (error) in
    print("ERROR: Recording failed for walkie talkie.")
}

Conclusion

Congratulations! You have now added live audio to your application with a few lines of code using the Voxer SDK. If you don’t have access to a Voxer Developer Portal you can sign up to join the beta program here: https://get.voxer.com/sdk/

 

Spread the love