SIGN UP

Using iOS SDK

This guide provides you to make the simplest application to make audio calls. You can start by downloading our demo application

Demo application with CallKit integration

iOS SDK has three dependencies, you can check them directly in the cocoapods site.

You can make and receive calls using your device’s data connection to/from any other endpoint that works with Voximplant: other mobile app built using Voximplant Mobile SDK, a web application built using the Web SDK, SIP phones and phone numbers all over the world.

 

Adding SDK to your application using Cocoapods

  • Install the CocoaPods (see getting starting guide)
  • Follow the instructions to create or modify Podfile
  • Add VoxImplantSDK dependency to your traget in Podfile
    target 'MyApp' do
      //other dependencies and configurations
      pod 'VoxImplantSDK'
    end
  • Run "pod install" command in terminal from your project directory
    pod install
  • Open the *.xcworkspace that was created. This should be the file you use everyday to create your app

You can see the example of Podfile in demo's repository.

 

Initializing SDK

Include the NSMicrophoneUsageDescription and NSCameraUsageDescription keys in your app's Info.plist file and provide a purpose strings for this keys. If your app attempts to access any of the device’s microphones or cameras without a corresponding purpose strings, your app exits. 

You also have to declare four Background Modes:

  • Audio and AirPlay
  • Background fetch
  • Remote notifications
  • Voice over IP

Enabling the Background Modes option adds the UIBackgroundModes key to your app’s Info.plist file. Selecting checkboxes in Xcode adds the corresponding background mode values to that key. 

 

Then create VIClient instance and initialize it as specified in documentation:

Swift

let client = VIClient(delegateQueue: DispatchQueue.main)

Objective-C

VIClient *client = [[VIClient alloc] 
  initWithDelegateQueue:dispatch_get_main_queue()];

 

Logging in

Firstly you need to connect to the Voximplant cloud. As a result the clientSessionDidConnect: or client:sessionDidFailConnectWithError: event will be sent to VIClientSessionDelegate. After connection is established, use the loginWithUser:password:success:failure: function to authenticate. For example, when you need to login user myuser to applcation myapp in your Voximplant account named myaccount with password mypass

Swift

class SomeClass : NSObject, VIClientSessionDelegate, VIClientCallManagerDelegate {
    var client : VIClient?
    var call : VICall?
 
    override init() {
        super.init()
 
        self.client = VIClient(delegateQueue: DispatchQueue.main)
        self.client?.sessionDelegate = self
        self.client?.connect()
    }
 
    func clientSessionDidConnect(_ client: VIClient!) {
        NSLog("Connection established")
 
        // For other login methods please see the article:
        // https://voximplant.com/blog/using-tokens-to-avoid-password-save
        self.client?.login(withUser: "myuser@myapp.myaccount.voximplant.com",
                           password: "mypass",
                            success: {
                              (displayName, authParams) in
                               NSLog("Login success")
        },
                            failure: {
                              error in
                              NSLog("Login failed")
        })
    }
}

Objective-C

@interface SomeClass () <VIClientSessionDelegate, VIClientCallManagerDelegate>
 
@property (strong, nonatomic) VIClient *client;
@property (strong, nonatomic) VICall *call;
 
@end
 
@implementation SomeClass
 
- (instancetype)init {
    self = [super init];
 
    if (self) {
        self.client = [[VIClient alloc] 
          initWithDelegateQueue:dispatch_get_main_queue()];
        self.client.sessionDelegate = self;
        [self.client connect];
    }
 
    return self;
}
 
- (void)clientSessionDidConnect:(VIClient *)client {
    NSLog(@"Connection established");
 
    // For other login methods please see the article:
    // https://voximplant.com/blog/using-tokens-to-avoid-password-save
    [client loginWithUser:@"myuser@myapp.myaccount.voximplant.com"
                 password:@"mypass"
                  success:^(NSString *displayName, NSDictionary *authParams) {
                      NSLog(@"Login succeeded");
                  }
                  failure:^(NSError *error) {
                      NSLog(@"Login failed with error %@", error.localizedDescription);
                  }];
}
@end

 

Making calls

To make an outbound audio call you need to run following code sequence:

Swift

func makeTestCall() {
    let call = self.client?.call(toUser: "to",
                                 withSendVideo: false,
                                 receiveVideo: false,
                                 customData: nil)
    call!.start(withHeaders: nil)
}

Objective-C

- (void)makeTestCall {
    VICall *call = [_client callToUser:@"to"
                         withSendVideo:NO
                          receiveVideo:NO
                            customData:nil];
    [call startWithHeaders:nil];
}

Please note that call is actually initiated only when you call the appropriate method (see the last line in the examples).

 

Receiving calls

You have to set delegate VIClientCallManagerDelegate to handle an incoming call. When application receives incoming call, the client:didReceiveIncomingCall:withIncomingVideo:headers: event is sent to your delegate. If you need to answer the call, you have to use following code:

Swift

func client(_ client: VIClient!, 
            didReceiveIncomingCall call: VICall!, 
            withIncomingVideo video: Bool, 
            headers: [AnyHashable : Any]!) {
    call.answer(withSendVideo: video, 
                receiveVideo: video, 
                customData: nil, 
                headers: nil)
}

Objective-C

- (void)        client:(VIClient *)client
didReceiveIncomingCall:(VICall *)call
     withIncomingVideo:(BOOL)video
               headers:(NSDictionary *)headers {
    [call answerWithSendVideo:video 
                 receiveVideo:video 
                   customData:nil 
                      headers:nil];
}

 

Terminating calls

Using the hangupWithHeaders: method allows to terminate the call properly. Both participants will receive the call:didDisconnectWithHeaders:answeredElsewhere: event after hangup's call will be executed.

Swift

func hangUp() {
    self.call?.hangup(withHeaders: nil)
}

Objective-C

- (void)hangUp {
    [self.call hangupWithHeaders:nil];
}

 

For more information, please read our reference documentation.

Get your free developer account or talk with our sales team to learn more about Voximplant solutions
SIGN UP
Contact sales

Please complete this field.

Please complete this field.

Please complete this field.

Choose the solution

Please complete this field.

Please complete this field.