Use this guide to quickly start a basic voice call demo with the Agora Voice SDK for macOS.
The following figure shows the workflow of a voice call implemented by the Agora SDK.
As shown in the figure, the workflow for adding Voice Call in your project is as follows:
Retrieve a token
A token is the credential that authenticates a user when your app client joins a channel. In a test or production environment, your app client retrieves tokens from a server in your security infrastructure.
Join a channel
Call joinChannel
to create and join a channel. App clients that pass the same channel name join the same channel.
Publish and subscribe to audio in the channel
After joining a channel, the app client automatically publishes and subscribes to audio in the channel.
For an app client to join an RTC channel, you need the following information:
Open Xcode, and click Create a new Xcode project.
Choose macOS as the target platform, App as the template, and click Next.
Input the project information, such as the product name, team, organization name, and language, and click Next.
Choose the storage path of the project, and click Create.
Choose one of the following methods to obtain the Agora macOS SDK:
Ensure that you have installed CocoaPods before the following steps. See the installation guide in Getting Started with CocoaPods.
In Terminal, navigate to the project path, and run the pod init
command to create a Podfile
in the project folder.
Open the Podfile
, delete all contents, and input the following codes. Remember to replace Your App
with the target name of your project.
# platform :macos, '10.11'
target 'Your App' do
pod 'AgoraRtcEngine_macOS'
end
Return to Terminal, and run the pod install
command to install the Agora SDK. Once you successfully install the SDK, it shows Pod installation complete!
in Terminal, and you can see an xcworkspace
file in the project folder.
Open the generated xcworkspace
file.
Navigate to SDK Downloads, download the latest version of the Agora macOS SDK, and extract the files from the downloaded SDK package.
According to your requirements, copy the libraries from the libs
folder of the SDK to the ./project_name
folder in your project (project_name
is an example of your project name).
Open Xcode, and navigate to TARGETS > Project Name > General > Frameworks, Libraries, and Embedded Content.
Click + > Add Other… > Add Files to add the corresponding libraries. Ensure that the Embed attribute of these dynamic libraries is Embed & Sign.
In Xcode, go to File > Swift Packages > Add Package Dependencies..., and paste the following URL:
https://github.com/AgoraIO/AgoraAudio_macOS
In Choose Package Options, specify the SDK version that you want to integrate. If the version number is x.y.z, fill in x.y.z; if the version number is x.y.z.a, fill in x.y.z-r.a.
Once you have integrated the Agora macOS SDK into your project, you need to call the core APIs provided by the Agora macOS SDK in the ViewController
file to implement basic voice call. The API call sequence is shown in the following figure:
Before calling any Agora API, import the AgoraRtcKit
class, and define agoraKit
.
// ViewController.h
// Imports the AgoraRtcKit class
// For SDKs earlier than 3.0.0, AgoraRtcKit is named AgoraRtcEngineKit
// If you use a SDK earlier than 3.0.0, use "#import <AgoraRtcEngineKit/AgoraRtcEngineKit.h>" instead
#import <AgoraRtcKit/AgoraRtcEngineKit.h>
// Specifies AgoraRtcEngineDelegate for monitoring a callback
@interface ViewController : NSViewController <AgoraRtcEngineDelegate>
// Defines agoraKit
@property (strong, nonatomic) AgoraRtcEngineKit *agoraKit;
// ViewController.swift
// Imports the AgoraRtcKit class
// For SDKs earlier than 3.0.0, AgoraRtcKit is named AgoraRtcEngineKit
// If you use a SDK earlier than 3.0.0, use "import AgoraRtcEngineKit" instead
import AgoraRtcKit
class ViewController: NSViewController {
...
// Defines agoraKit
var agoraKit: AgoraRtcEngineKit?
}
Call the sharedEngineWithAppId
method to create and initialize the AgoraRtcEngineKit
object.
When adding the following code in your project, replace YourAppID
with the App ID of your project. See Get an App ID.
If you want to monitor a callback for your app scenario, register it when initializing AgoraRtcEngineKit
.
// ViewController.m
// Types the followiing code in the function you defines, such as viewDidLoad()
self.agoraKit = [AgoraRtcEngineKit sharedEngineWithAppId:@"YourAppID" delegate:self];
// ViewController.swift
// Types the followiing code in the function you defines, such as viewDidLoad()
agoraKit = AgoraRtcEngineKit.sharedEngine(withAppId: "YourAppID", delegate: self)
Call the joinChannelByToken
method to join a channel. When adding the following code in your project, replace YourToken
with the token of your project, and replace YourChannelName
with the channel name used to generate the token of your project.
// ViewController.m
// Types the followiing code in the function you defines, such as viewDidLoad()
// The uid of each user in the channel must be unique.
[self.agoraKit joinChannelByToken:@"YourToken" channelId:@"YourChannelName" info:nil uid:0 joinSuccess:^(NSString * _Nonnull channel, NSUInteger uid, NSInteger elapsed) {
}];
// ViewController.swift
// Types the followiing code in the function you defines, such as viewDidLoad()
// The uid of each user in the channel must be unique.
agoraKit?.joinChannel(byToken: "YourToken", channelId: "YourChannelName", info: nil, uid: 0, joinSuccess: { (channel, uid, elapsed) in
})
Call the leaveChannel
method when you need to leave the channel, for example, to end the call, close the app, or run the app in the background.
// ViewController.m
// Types the followiing code in the function you defines
[self.agoraKit leaveChannel:nil];
// ViewController.swift
// Types the followiing code in the function you defines
agoraKit?.leaveChannel(nil)
After leaving the channel, if you want to release all resources used by the Agora SDK, call the destroy
method to destroy the AgoraRtcEngineKit
object.
// ViewController.m
// Types the followiing code in the function you defines
[AgoraRtcEngineKit destroy];
// ViewController.swift
// Types the followiing code in the function you defines
AgoraRtcEngineKit.destroy()
Before running the project, you need to set your signing and team, and add device permissions.
info.plist
file. Add the following contents to add permissions for your device:Key | Type | Value |
---|---|---|
Privacy - Microphone Usage Description | String | The purpose for accessing the microphone, such as for a call or interactive live streaming. |
Capability | Category | Permission |
---|---|---|
App Sandbox | Network |
|
App Sandbox | Hardware | Audio Input |
Hardened Runtime | Resource Access | Audio Input |
Agora recommends running the project on a real device instead of a simulator.
To test the remote audio, visit the Web Demo, and enter the same App ID, channel name, and token to join the same channel. You should hear the remote user when you successfully start a one-to-one voice call in the app.
Choose one of the following methods to integrate a version of the Agora macOS SDK earlier than v3.2.0.
Ensure that you have installed CocoaPods before performing the following steps. See the installation guide in Getting Started with CocoaPods.
In Terminal, navigate to the project path, and run the pod init
command to create a Podfile
in the project folder.
Podfile
, delete all contents, and input the following codes. Remember to replace Your App
with the target name of your project and replace version
with the version of the SDK that you want to integrate. For information about the SDK version, see Release Notes.# platform :macos, '10.11'
target 'Your App' do
pod 'AgoraRtcEngine_macOS', 'version'
end
Return to Terminal, and run the pod install
command to install the Agora SDK. Once you successfully install the SDK, it shows Pod installation complete!
in Terminal, and you can see an xcworkspace
file in the project folder.
Open the generated xcworkspace
file.
You need to use different integration methods to integrate different versions of the SDK. Click the following version categories to expand the corresponding integration steps.
AgoraRtcKit.framework
, Agorafdkaac.framework
, and AgoraSoundTouch.framework
dynamic libraries to the ./project_name
folder in your project (project_name
is an example of your project name).Click + > Add Other… > Add Files to add the AgoraRtcKit.framework
, Agorafdkaac.framework
, and AgoraSoundTouch.framework
dynamic libraries. Ensure that the Embed attribute of these dynamic libraries is Embed & Sign.
Once these dynamic libraries are added, the project automatically links to other system libraries.
Copy the AgoraRtcKit.framework
dynamic library to the ./project_name
folder in your project (project_name
is an example of your project name).
Open Xcode, and navigate to TARGETS > Project Name > General > Frameworks, Libraries, and Embedded Content.
Click + > Add Other… > Add Files to add the AgoraRtcKit.framework
dynamic library. Ensure that the Embed attribute of the dynamic library is Embed & Sign. Once the dynamic library is added, the project automatically links to other system libraries.
In v3.0.0, the SDK package contains an AgoraRtcKit.framework
dynamic library and an AgoraRtcKit.framework
static library. Choose which of these libraries to add according to your needs.
The paths of the two libraries in the SDK package are as follows:
./Agora_Native_SDK_for_macOS_..._Dynamic/libs
../Agora_Native_SDK_for_macOS_.../libs
.Integrate the dynamic library:
Copy the AgoraRtcKit.framework
dynamic library from the ./libs
path of the SDK package to the ./project_name
folder in your project (project_name
is an example of your project name).
Open Xcode, and navigate to TARGETS > Project Name > General > Frameworks, Libraries, and Embedded Content.
Click + > Add Other… > Add Files to add the AgoraRtcKit.framework
dynamic library. Ensure that the Embed attribute of the dynamic library is Embed & Sign.
Once the dynamic library is added, the project automatically links to other system libraries.
Integrate the static library:
AgoraRtcKit.framework
static library from the ./libs
path of the SDK package to the ./project_name
folder in your project (project_name
is an example of your project name).AgoraRtcKit.framework
static library, you need to click +, and then click Add Other....SDK | Library |
---|---|
Voice SDK | AgoraRtcKit.framework Accelerate.framework CoreWLAN.framework libc++.tbd libresolv.9.tbd SystemConfiguration.framework |
Video SDK | AgoraRtcKit.framework Accelerate.framework CoreWLAN.framework libc++.tbd libresolv.9.tbd SystemConfiguration.framework VideoToolbox.framework |
AgoraRtcEngineKit.framework
static library from the ./libs
path of the SDK package to the ./project_name
folder in your project (project_name
is an example of your project name).AgoraRtcEngineKit.framework
static library, you need to click +, and then click Add Other....SDK | Library |
---|---|
Voice SDK | AgoraRtcEngineKit.framework Accelerate.framework CoreWLAN.framework libc++.tbd libresolv.9.tbd SystemConfiguration.framework |
Video SDK | AgoraRtcEngineKit.framework Accelerate.framework CoreWLAN.framework libc++.tbd libresolv.9.tbd SystemConfiguration.framework VideoToolbox.framework |
When integrating the Agora Voice SDK, you can also refer to the following articles: