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 IM 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

Objective C
NCCallEngine *engine = [NCCallEngine sharedInstance];

// Recommended once during app startup
[engine install];

After Chat SDK initialization and IM sign-in are complete, call initialize::

Objective C
INCCallInitOptions *options = [INCCallInitOptions new];
options.pubLowResolutionStream = YES;
options.enableHardwareEncoderHighProfile = NO;

BOOL initialized = [[NCCallEngine sharedInstance] initialize:options];

Step 3: Register delegates

Set the event delegate before IM connects so that you can receive restored call events as early as possible.

Objective C
@interface MyCallHandler () <NCCallEventDelegate, NCCallAPIResultDelegate>
@end

@implementation MyCallHandler

- (void)setupCallDelegates {
NCCallEngine *engine = [NCCallEngine sharedInstance];
[engine setCallEventsDelegate:self];
[engine setAPIResultListener: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.isTiny = NO;

NCCallEngine *engine = [NCCallEngine sharedInstance];
[engine setVideoView:localView];
[engine setVideoView:remoteView];

Step 5: Start a call

Objective C
[[NCCallEngine sharedInstance] startCall:@[self.remoteUserId]
callType:NCCallSingleType
mediaType:NCCallAudioVideoMediaType];

Step 6: Accept or end the call

On the callee side, accept the call in didCallReceived:extra::

Objective C
- (void)didCallReceived:(NCCallSession *)session extra:(NSString *)extra {
[[NCCallEngine sharedInstance] acceptCall:session.callId];
}

To end the call, use:

Objective C
[[NCCallEngine sharedInstance] endCall];
// Or
[[NCCallEngine sharedInstance] endCall:callId];

Step 7: Control devices during the call

Objective C
NCCallEngine *engine = [NCCallEngine sharedInstance];

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