Skip to main content

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
tip

To set up CocoaPods, see Installing CocoaPods.

Step 1: Add the framework

NexconnCall supports remote dependency integration through CocoaPods.

  1. If your project does not have a Podfile, open Terminal, go to the project root, and run pod init. Then add the following entry to the generated Podfile:

    ruby
    pod 'NexconnCall/Call'
  2. In the directory that contains the Podfile, run:

    shell
    pod install
    tip

    If Terminal reports that the required version cannot be found, run pod repo update first and then run pod install again.

  3. Open the generated .xcworkspace file in Xcode.

Step 2: Install and initialize the Call SDK

Recommended order:

  1. [NCCallEngine install] — Register with the Chat bridge. Must run before NexconnChat and NexconnCall are initialized. Call once at app startup.

    Objective C
    [NCCallEngine install];
  2. NexconnChat — Initialize the Chat SDK, for example:

    Objective C
    NCInitParams *params = [[NCInitParams alloc] initWithAppKey:@"appKey"];
    [NCEngine initializeWithParams:params];

    Then complete Chat connection and sign-in using your existing Chat flow.

  3. NexconnCall — After Chat is initialized and the user is signed in, configure the engine and call initialize::

    Objective C
    NCCallInitParams *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.

Objective C
@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

Objective C
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::

Objective C
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:

Objective C
- (void)onCallReceived:(NCCallReceivedEvent *)event {
NCCallAcceptCallParams *accept =
[[NCCallAcceptCallParams alloc] initWithCallId:event.session.callId];
[[NCCallEngine getInstance] acceptCall:accept];
}

To end the call:

Objective C
NCCallEndCallParams *endParams = [[NCCallEndCallParams alloc] initWithCallId:session.callId];
endParams.pushConfig = nil;
[[NCCallEngine getInstance] endCall:endParams];

Step 7: Control devices during the call

Objective C
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