logo
On this page

Quick start (with call invitation)

Prerequisites

​If you don't know how to create a project and obtain an app ID, please refer to this guide.

Prepare the environment

Before you attempt to integrate the SDK, make sure that the development environment meets the following requirements:

  • Xcode 15.0 or higher version.
  • iOS 12.0 or higher version and iOS devices that support audio and video.
  • The iOS device is connected to the Internet.

Add ZegoUIKitPrebuiltCall as dependencies

  • Open Terminal, navigate to your project's root directory, and run the following to create a podfile:
    pod init
  • Edit the Podfile file to add the basic dependencies:
    pod 'ZegoUIKitPrebuiltCall'
    pod 'ZegoUIKitSignalingPlugin'
    pod 'ZegoUIKitAppleCallKitPlugin'
  • In Terminal, run the following to download all required dependencies and SDK with Cocoapods:
    pod install

Integrate the SDK with the call invitation feature

Initialize the call invitation service

Call the init method on the App startup, and specify the userID and userName for connecting the Call Kit service.

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Get your AppID and AppSign from ZEGOCLOUD's Console
        // userID can only contain numbers, letters, and '_'. 
        let config = ZegoUIKitPrebuiltCallInvitationConfig(notifyWhenAppRunningInBackgroundOrQuit: true, isSandboxEnvironment: false)
        ZegoUIKitPrebuiltCallInvitationService.shared.initWithAppID(YOUR_APPID, appSign: YOUR_APP_SIGN, userID:YOUR_USER_ID, userName:YOUR_USER_NAME, config: config, callback: { errorCode, message in
        
        })
    }
}

Parameters of ZegoUIKitPrebuiltCallInvitationConfig class

ParameterTypeRequiredDescription
incomingCallRingtoneStringNoSet the ringtone for incoming call invitations.
outgoingCallRingtoneStringNoSet the ringtone for outgoing call invitations.
showDeclineButtonBoolNoSet the display or hide for the decline button.
notifyWhenAppRunningInBackgroundOrQuitBoolNoChange notifyWhenAppRunningInBackgroundOrQuit to false if you don't need to receive a call invitation notification when your app is running in the background or the user has quitted the app.
isSandboxEnvironmentBoolNoTo publish your app to TestFlight or App Store, set the isSandboxEnvironment to false before starting building. To debug locally, set it to true. Ignore this when the notifyWhenAppRunningInBackgroundOrQuit is false.
certificateIndexEnumNoTo configure different certificates for different bunldle ID applications. The certificateIndex can be set as firstCertificate or secondCertificate, defaults to firstCertificate.
translationTextZegotranslationTextNoTo modify the UI text, use this property. For more details, see Custom prebuilt UI.
videoConfigZegoPrebuiltCallVideoConfig.PRESET_360PThis parameter is used to configure the push-pull flow resolution.

Parameters of ZegoUIKitPrebuiltCallInvitationService class

ParameterTypeRequiredDescription
appIDStringYesThe App ID you get from ZEGOCLOUD Admin Console.
appSignStringYesThe App Sign you get from ZEGOCLOUD Admin Console.
userIDStringYesuserID can be something like a phone number or the user ID on your own user system. userID can only contain numbers, letters, and underlines (_).
userNameStringYesuserName can be any character or the user name on your own user system.
configZegoUIKitPrebuiltCallInvitationConfigYesThis can be used to set up call invitation related configurations.

Add the button for making call invitation

You can customize the position of the ZegoSendCallInvitationButton accordingly, pass in the ID of the user you want to call.

  1. Set up a button for making a voice call.
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    
        // Create Voice Call invitation Button
        let callTargetUser: ZegoUIKitUser = ZegoUIKitUser.init("TargetUserID", "TargetUserName")
        let sendVoiceCallButton: ZegoSendCallInvitationButton = ZegoSendCallInvitationButton(ZegoInvitationType.voiceCall.rawValue)
        sendVoiceCallButton.text = "voice"
        sendVoiceCallButton.setTitleColor(UIColor.blue, for: .normal)
        sendVoiceCallButton.inviteeList.append(callTargetUser)
        sendVoiceCallButton.resourceID = "zegouikit_call" // For offline call notification
        sendVoiceCallButton.frame = CGRect.init(x: 100, y: 100, width: 100, height: 30)
        // Add the button to your view
        self.view.addSubview(sendVoiceCallButton)
    }
}
  1. Set up a button for making a video call.
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
 
        // Create Video Call invitation Button
        let callTargetUser: ZegoUIKitUser = ZegoUIKitUser.init("TargetUserID", "TargetUserName")
        let sendVideoCallButton: ZegoSendCallInvitationButton = ZegoSendCallInvitationButton(ZegoInvitationType.videoCall.rawValue)
        sendVideoCallButton.text = "Video"
        sendVideoCallButton.setTitleColor(UIColor.blue, for: .normal)
        sendVideoCallButton.resourceID = "xxx" // For offline call notification
        sendVideoCallButton.frame = CGRect.init(x: 100, y: 100, width: 100, height: 30)
        sendVideoCallButton.inviteeList.append(callTargetUser)
        // Add the button to your view.
        self.view.addSubview(sendVideoCallButton)
    }
}

Parameters of ZegoSendCallInvitationButton class

ParameterTypeRequiredDescription
inviteeListArrayYesThe information of the callee. userID and userName are required. For example: [{ userID: inviteeID, userName: inviteeName }]
typeintYesIf the type is set to ZegoInvitationType.videoCall.rawValue, a video call is made when the button is pressed. If the type is set to other values, a voice call is made.
resourceIDStringNoresourceID can be used to specify the ringtone of an offline call invitation, which must be set to the same value as the Push Resource ID in ZEGOCLOUD Admin Console. This only takes effect when the notifyWhenAppRunningInBackgroundOrQuit is true.
timeoutUInt32NoThe timeout duration. It's 60 seconds by default.

For more parameters, go to Custom prebuilt UI.

Now, you can make call invitations by simply clicking on the buttons you set.

Customer call button

If the user does not want to use the ZegoSendCallInvitationButton provided by CallKit internally and wants to use a custom button instead, CallKit provides a method to initiate a call.

This feature is supported in versions 2.12.0 and later.

  1. Edit the Podfile file and add the basic dependencies:
    pod 'ZegoUIKitPrebuiltCall' '>= 2.12.1'
  2. Run the following command in the terminal to download all necessary dependencies and SDK using Cocoapods:
    pod install
  3. Call the following method in the click event of the custom audio/video call button:
    let user: ZegoPluginCallUser = ZegoPluginCallUser(userID: "userID", userName: "userName")
    let notificationConfig: ZegoPluginCallNotificationConfig = ZegoSignalingPluginNotificationConfig(resourceID: "resourceID")
    ZegoPluginAdapter.callPlugin?.sendInvitationWithUIChange(invitees: [user], invitationType: type == .voiceCall ? .voiceCall : .videoCall, customData: "", timeout: 60, notificationConfig: notificationConfig), callback: { data in
                
    })

API

/// Initiate an audio or video call
/// - Parameters:
///   - invitees: List of users to invite to the call
///   - invitationType: Type of call. Audio or video
///   - customData: Custom data
///   - timeout: Timeout duration
///   - notificationConfig: Offline notification information
///   - callback: Callback function
func sendInvitationWithUIChange( invitees:[ZegoPluginCallUser],invitationType: ZegoPluginCallType,
                                     customData: String, timeout: Int, notificationConfig: ZegoSignalingPluginNotificationConfig,
                                     callback: ZegoPluginCallback?) {

}

Configure your project

1. Apple Developer Center and ZEGOCLOUD Console Configuration

  • step1. You need to refer to Create VoIP services certificates to create the VoIP service certificate, and ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​export a .p12 file on your Mac.
  • step2. Add the voip service certificate .p12 file. Then, create a resource ID;

In the create resource ID popup dialog, you should switch to the VoIP option for APNs, and switch to Data messages for FCM.

When you have completed the configuration, you will obtain the resourceID. You can refer to the image below for comparison.

2. Add app permissions

Open the Info.plist file and add the following:

<key>NSCameraUsageDescription</key>
<string>We need to use the camera</string>
<key>NSMicrophoneUsageDescription</key>
<string>We need to use the microphone</string>

3. Get the APNs device token

  • step1. In the AppDelegate.swift file, implement Apple's register callback for receiving the deviceToken:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data){

}
  • step2. In the didRegisterForRemoteNotificationsWithDeviceToken callback, call the setRemoteNotificationsDeviceToken method to get the deviceToken:
import ZegoUIKitPrebuiltCall

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
/// Required - Set the device token
  ZegoUIKitPrebuiltCallInvitationService.setRemoteNotificationsDeviceToken(deviceToken)
}

4. Add Push Notifications configuration

Open the project with Xcode, and click the+ Capability on the Signing & Capabilities page.

And double-click on Push Notifications to add this feature.

5. Add the Background Modes capability.

Open the project with Xcode, and click the+ Capability on the Signing & Capabilities page again.

And double-click on Background Modes in the pop-up window. This will allow you to see the Background Modes configuration in the Signing & Capabilities.

6. Check and Make sure the following features are enabled

7. Import the PushKit and CallKit libraries.

Run & Test

Now you have finished all the steps!

You can simply click the Run in XCode to run and test your App on your device.

Resources

Previous

Quick start

Next

Overview