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
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
NCCallEngine *engine = [NCCallEngine sharedInstance];
// Recommended once during app startup
[engine install];
After Chat SDK initialization and IM sign-in are complete, call initialize::
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.
@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
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
[[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::
- (void)didCallReceived:(NCCallSession *)session extra:(NSString *)extra {
[[NCCallEngine sharedInstance] acceptCall:session.callId];
}
To end the call, use:
[[NCCallEngine sharedInstance] endCall];
// Or
[[NCCallEngine sharedInstance] endCall:callId];
Step 7: Control devices during the call
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
- 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.