- Documentation
- Call Kit
- Quick start
- Quick start (with call invitation)
Quick start (with call invitation)
Prerequisites
- Go to ZEGOCLOUD Admin Console to create a UIKit project.
- Get the AppID and AppSign of the project.
If you don't know how to create a project and obtain an app ID, please refer to this guide.
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'
- 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)
}
}
Parameters of ZegoUIKitPrebuiltCallInvitationConfig class
Parameter | Type | Required | Description |
---|---|---|---|
incomingCallRingtone |
String |
No |
This parameter has been deprecated. |
outgoingCallRingtone |
String |
No |
If you want to set the call ringtone for receiving incoming call invitations or sending outgoing call invitations, you can use the incomingCallRingtone and outgoingCallRingtone . |
notifyWhenAppRunningInBackgroundOrQuit |
Bool |
No |
Change notifyWhenAppRunningInBackgroundOrQuit to false if you don't need to receive a call invitation notification while your app running in the background or quit. |
isSandboxEnvironment |
Bool |
No |
To 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. |
certificateIndex |
Enum |
No |
To configure different certificates for different bunldle ID applications. The certificateIndex can be set as firstCertificate or secondCertificate , defaults to firstCertificate . |
showDeclineButton |
Bool |
No |
This parameter has been deprecated. |
innerText |
ZegoInnerText |
No |
To modify the UI text, use this property. For more details, see Custom prebuilt UI. |
Parameters of ZegoUIKitPrebuiltCallInvitationService class
Parameter | Type | Required | Description |
---|---|---|---|
appID |
String |
Yes |
The App ID you get from ZEGOCLOUD Admin Console. |
appSign |
String |
Yes |
The App Sign you get from ZEGOCLOUD Admin Console. |
userID |
String |
Yes |
userID can be something like a phone number or the user ID on your own user system. userID can only contain numbers, letters, and underlines (_). |
userName |
String |
Yes |
userName can be any character or the user name on your own user system. |
config |
ZegoUIKitPrebuiltCallInvitationConfig |
Yes |
This can be used to set up call invitation related configurations. |
Add the button for making call invitations
You can customize the position of the ZegoSendCallInvitationButton
accordingly, pass in the ID of the user you want to call.
- 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: 150, height: 40)
// Add the button to your view
self.view.addSubview(sendVoiceCallButton)
}
}
- 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.inviteeList.append(callTargetUser)
sendVideoCallButton.resourceID = "zegouikit_call" // For offline call notification
sendVideoCallButton.frame = CGRect.init(x: 100, y: 100, width: 150, height: 40)
// Add the button to your view.
self.view.addSubview(sendVideoCallButton)
}
}
Parameters of ZegoSendCallInvitationButton class
Parameter | Type | Required | Description |
---|---|---|---|
inviteeList |
Array |
Yes |
The information of the callee. userID and userName are required. For example: [{ userID: inviteeID, userName: inviteeName }] |
type |
int |
Yes |
If 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. |
resourceID |
String |
No |
resourceID 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. |
timeout |
UInt32 |
No |
The 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.
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 my_project/ios/my_project/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 thedeviceToken
:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data){
}
- step2. In the
didRegisterForRemoteNotificationsWithDeviceToken
callback, call thesetRemoteNotificationsDeviceToken
method to get thedeviceToken
:
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.