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:
    Untitled
    pod init
    
    1
    Copied!
  • Edit the Podfile file to add the basic dependencies:
    Untitled
    pod 'ZegoUIKitPrebuiltCall'
    pod 'ZegoUIKitSignalingPlugin'
    pod 'ZegoUIKitAppleCallKitPlugin'
    
    1
    Copied!
  • In Terminal, run the following to download all required dependencies and SDK with Cocoapods:
    Untitled
    pod install
    
    1
    Copied!

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.

swift
objc
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)
    }
}
1
Copied!
#import "ViewController.h"

@import ZegoUIKit;
@import ZegoUIKitPrebuiltCall;
@import ZegoUIKitSignalingPlugin;
@import ZegoPluginAdapter;

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  // Get your AppID and AppSign from ZEGOCLOUD's Console
  // userID can only contain numbers, letters, and '_'. 
  // certificateIndex: indicates the signaling formation certificate verification method
  ZegoUIKitPrebuiltCallInvitationConfig *config = [[ZegoUIKitPrebuiltCallInvitationConfig alloc] initWithNotifyWhenAppRunningInBackgroundOrQuit:YES isSandboxEnvironment:YES certificateIndex:ZegoSignalingPluginMultiCertificateFirstCertificate];

  [[ZegoUIKitPrebuiltCallInvitationService shared] initWithAppID:YOUR_APPID appSign:YOUR_APP_SIGN userID:YOUR_USER_ID userName:YOUR_USER_NAME config:config];
}
1
Copied!

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.
swift
objc
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
Copied!
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Create Voice Call invitation Button
    ZegoUIKitUser *callTargetUser = [[ZegoUIKitUser alloc] initWithUserID:@"TargetUserID" userName:@"TargetUserName" isCameraOn:NO isMicrophoneOn:YES];
    ZegoSendCallInvitationButton *sendVoiceCallButton = [[ZegoSendCallInvitationButton alloc] initWithInvitationType:ZegoInvitationTypeVoiceCall];
    sendVoiceCallButton.frame = CGRectMake(100, 100, 100, 30);
    [sendVoiceCallButton setText:@"voice"];
    [sendVoiceCallButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    sendVoiceCallButton.resourceID = @"xxx";
    sendVoiceCallButton.inviteeList = @[allTargetUser];
    // Add the button to your view
    [self.view addSubview:sendVoiceCallButton];
}
1
Copied!
  1. Set up a button for making a video call.
swift
objc
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)
    }
}
1
Copied!
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    ZegoUIKitUser *user = [[ZegoUIKitUser alloc] initWithUserID:@"user id" userName:@"user nickname" isCameraOn:YES isMicrophoneOn:YES];

    // Create video call invitation button.
    ZegoSendCallInvitationButton * sendVideoCallButton = [[ZegoSendCallInvitationButton alloc] initWithInvitationType:ZegoInvitationTypeVideoCall];
    sendVideoCallButton.frame = CGRectMake(100, 100, 100, 30);
    [sendVideoCallButton setText:@"Video"];
    sendVideoCallButton.resourceID = @"xxx";
    sendVideoCallButton.inviteeList = @[user];
    // Add the button to your view.
    [self.view addSubview:sendVideoCallButton];
}
1
Copied!

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

API

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:

Untitled
<key>NSCameraUsageDescription</key>
<string>We need to use the camera</string>
<key>NSMicrophoneUsageDescription</key>
<string>We need to use the microphone</string>
1
Copied!

3. Get the APNs device token

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

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

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

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