Sync Audio SDK for iOS: Quickstart
With the Sync Audio SDK for iOS, you can quickly add high-quality, real-time voice chat to your app. Sync SDKs offer a ready-to-use, best-in-class user experience that you can customize completely.
This SDK uses our advanced media optimization and adaptation framework and our world-wide media distribution system.
It provides high-quality, low-latency multi-party voice chat with up to 24 users speaking. Its responsive design automatically handles a wide variety of screen sizes and form factors.
The prebuilt UI panel has expanded and collapsed states:
Try it now
To see this SDK in action in a production app, check out air.live:
Before starting
Minimum versions
iOS: 13.0
Xcode 13.3
Limitations
For M1 and M2 Macs, you must run Xcode using Rosetta.
As of Xcode 14, bitcode is deprecated. With older versions of Xcode, turn off bitcode in your project's build settings to use this SDK.
Install the SDK
Open the Xcode workspace for your app.
Click File, then click Add Packages.
Copy and paste this URL into the search box:
https://github.com/aircoreio/aircore-media-panel-ios
Select the Up to Next Major Version dependency rule.
Click Add Package.
You may see the Choose Package Products dialog. Click Add Package.
If you have issues with building after adding the package:
Open the File menu, then Packages, then click Reset Package Caches.
Request permissions
This SDK requests microphone permissions. To tell the user why the app needs access, you must set the NSMicrophoneUsageDescription
property.
Authenticate
This guide uses a publishable API key for a quick setup. To get your API key:
Create an app in the Developer Console.
Copy your publishable API key and use it in the next section.
For an overview of API keys, see Authentication.
Set up your app
Create the client
The Client
object is the primary controller that powers this SDK. The client can seamlessly integrate your existing user and channel models.
You can use the client to:
- Configure user metadata
- Join a channel to connect to a real-time session with other users
- Control logging
- Listen to events that happen behind the scenes
Use a publishable API key to create the client:
import AircoreMediaPanel
// Use a publishable API key directly from the Developer Console
let client = Client.create(publishableKey: key, userID: userID)
For more detailed security controls, you can use a secret API key instead. See Customization.
Set user properties
After creating the Client
, set these properties to represent the user:
client.userDisplayName = "Jane Doe"
client.userAvatarURL = URL(string: "http://user-profile-picture.png")
Set up the panel
Set up the UI text
Create a MediaPanelConfiguration
object to control the UI text and default behavior. You only need to specify the parameters that you want to customize.
let config = MediaPanelConfiguration(
// All parameters are optional. Add parameters that you want to customize.
panelTitle: "My Channel",
panelSubtitle: "My Channel is a happy space where people can have fun"
)
You can change any text on the panel. See Customize the UI text.
Set the theme
By default, the panel uses a light theme. To use a dark theme, create an optional Theme
object:
let myTheme = Theme.dark()
You can also create a custom theme. See Customize the theme.
Customize the user experience
To customize the user experience, you can choose which users can publish audio.
The panel shows all users as they join. By default, users start with a muted microphone. To start publishing audio, users tap the microphone button on the panel.
Create an audience
You can change the panel options and permissions to build an app in which some users speak and others just listen.
To create an audience, you can stop users from unmuting. To hide the microphone button, set showMicrophoneButton
to false
.
It's best to also keep the audience muted by using permissions. To do this, use a secret API key. You can't do this with a publishable API key because it lets all users publish audio.
To mute certain users, request and send out session auth tokens that don't allow publishing audio.
Token permissions don't affect the showMicrophoneButton
setting. If the setting is true
, users that can't publish audio can still see and press the button, but it doesn't do anything.
Automatically publish audio
To have users publish automatically, set autoPublishMicOnJoin
to true
.
Connect and show the panel
Connect to a channel
A channel represents a group of users. See Channels for a general overview.
To connect the client to a channel, use the connect()
method.
If you're using a secret API key, you need a session auth token that matches the channel. When you request a token, use the same channel ID.
client.connect(channelID: channel)
Create the panel object
You can now create the MediaPanel
object, which shows the panel in your existing view controller:
client.connect(channelID: channel)
let panel = MediaPanel(
client: client,
channelID: channel,
configuration: configuration,
theme: myTheme // Optional
)
panel.present(in: self, style: .bottomBar)
Disconnect and reconnect to a channel
You can disconnect and reconnect to the same channel.
To disconnect, call the disconnect()
method. To reconnect, call connect()
using the same channelID
.
// Disconnect from a channel
client.disconnect(fromChannelID: channel)
// Reconnect to the channel
client.connect(channelID: channel)
Switch to a new channel
To switch to a new channel, use a new client:
Tear down the panel and client objects (see Tear down and clean up below).
Start again with a new client (see Create the client above).
Respond to notifications and errors
You can subscribe to events and errors and respond accordingly:
client.on(.localUserJoined) { channelID, userID in
print("I just joined a call!")
}
client.onError { channelID, error in
// Handle any errors
}
See the complete references for events and errors.
Tear down and clean up
To tear down the panel and client:
// Tear down the panel
panel.destroy()
// Tear down the client
// This disconnects automatically from all connected channels
client.destroy()
More info
To continue customizing the panel, see Customization.
See the full API reference.
Download our sample apps.