Make your first call
This tutorial shows how to build a minimal calling integration in an iOS app.
Prerequisites
- Xcode 9.0 or later
- A physical iOS device running iOS 10.0 or later for audio and video call testing
- A completed Chat SDK initialization and Chat sign-in flow
- CocoaPods 1.10.0 or later if you integrate the SDK through CocoaPods, because the Call SDK uses XCFramework and full XCFramework support starts from CocoaPods 1.10.0
To set up CocoaPods, see Installing CocoaPods.
Step 1: Add the framework
NexconnCall supports remote dependency integration through CocoaPods.
-
If your project does not have a
Podfile, open Terminal, go to the project root, and runpod init. Then add the following entry to the generatedPodfile:rubypod 'NexconnCall/Call' -
In the directory that contains the
Podfile, run:shellpod installtipIf Terminal reports that the required version cannot be found, run
pod repo updatefirst and then runpod installagain. -
Open the generated
.xcworkspacefile in Xcode.
Step 2: Install and initialize the Call SDK
Recommended order:
-
[NCCallEngine install]— Register with the Chat bridge. Must run before NexconnChat and NexconnCall are initialized. Call once at app startup.Objective C[NCCallEngine install]; -
NexconnChat — Initialize the Chat SDK, for example:
Objective CNCInitParams *params = [[NCInitParams alloc] initWithAppKey:@"appKey"];
[NCEngine initializeWithParams:params];Then complete Chat connection and sign-in using your existing Chat flow.
-
NexconnCall — After Chat is initialized and the user is signed in, configure the engine and call
initialize::Objective CNCCallInitParams *initParams = [NCCallInitParams new];
initParams.pubLowResolutionStream = YES;
initParams.enableHardwareEncoderHighProfile = NO;
[[NCCallEngine getInstance] initialize:initParams];
Step 3: Register handlers
Set the call event handler before Chat connects so that you can receive restored call events as early as possible.
@interface MyCallHandler () <NCCallEventHandler, NCCallAPIResultHandler>
@end
@implementation MyCallHandler
- (void)setupCallHandlers {
NCCallEngine *engine = [NCCallEngine getInstance];
[engine setCallEventHandler:self];
[engine setAPIResultHandler:self];
}
@end
Step 4: Prepare video views
NCCallLocalVideoView *localView = [NCCallLocalVideoView new];
localView.userId = self.currentUserId;
localView.renderMode = NCCallRenderModeAspectFit;
NCCallRemoteVideoView *remoteView = [NCCallRemoteVideoView new];
remoteView.userId = self.remoteUserId;
remoteView.renderMode = NCCallRenderModeAspectFit;
remoteView.enableLowResolutionStream = NO;
NCCallEngine *engine = [NCCallEngine getInstance];
[engine setLocalVideoView:localView];
[engine setRemoteVideoView:@[ remoteView ]];
Step 5: Start a call
Use NCCallStartCallParams’s designated initializer, then pass the object to startCall::
NCCallStartCallParams *params =
[[NCCallStartCallParams alloc] initWithCalleeIds:@[ self.remoteUserId ]
callType:NCCallTypeSingle
mediaType:NCCallMediaTypeAudioVideo];
[[NCCallEngine getInstance] startCall:params];
Step 6: Accept, reject, or end the call
On the callee side, accept the call in onCallReceived: and read fields from NCCallReceivedEvent:
- (void)onCallReceived:(NCCallReceivedEvent *)event {
NCCallAcceptCallParams *accept =
[[NCCallAcceptCallParams alloc] initWithCallId:event.session.callId];
[[NCCallEngine getInstance] acceptCall:accept];
}
To end the call:
NCCallEndCallParams *endParams = [[NCCallEndCallParams alloc] initWithCallId:session.callId];
endParams.pushConfig = nil;
[[NCCallEngine getInstance] endCall:endParams];
Step 7: Control devices during the call
NCCallEngine *engine = [NCCallEngine getInstance];
engine.enableMicrophone = YES;
engine.enableSpeaker = YES;
[engine enableCamera:YES];
[engine switchCamera];
The current iOS header comments indicate that the camera is enabled by default after a video call is connected.
Next steps
- See 1-to-1 call for more 1-to-1 call APIs.
- See Group call for group calling APIs.
- See Configure push settings for push fields.
- See VoIP PushKit integration for VoIP-related behavior.