iOS

I. Setting up XCode project

Step 1: Download portsipSDK here

Step 2: Declare permission to use Microphone, Camera (for video calling) in the fileInfo.plist

Step 3: Add these libraries and frameworks to TARGETS → App Name in XCode

  • The VideoToolbox, MetalKit, GLKit, libresolv.tbd, libc++.tbd libraries are supported by XCode, just click the "+" sign and search for the library name and add it.

  • PortSIPVoIPSDK.frameworklocated in the folder iOSSampleextracted from the file .zipdownloaded in step 1.

Note TARGETS not PROJECT

Step 4: InBuild SettingsLinkingOther Linker Flags: add value-ObjC

Reference : https://www.portsip.com/docs/sdk/manual/portsip-voip-sdk-user-manual-ios.pdf

The examples from section II onwards are all applied in just one file: AppDelegate.swift

II. Initialize SDK

Step 1 : Declare global variablelet portsipSDK: PortSIPSDK! = PortSIPSDK(). Used to call PortsipSDK APIs.

Step 2: Open the fileRunner-Bridging-Header.h, import this line#import <PortSIPVoIPSDK/PortSIPVoIPSDK.h>

Step 3: Must implement interface:**PortSIPEventDelegate.** in ClassAppDelegate

Copy

This function should be called together with extension login.

III. Extension login

There should be a variable portsipRegisteredto save the status of whether the portip has been registered successfully or not. If the registration is successful, just call the API refreshRegistration(), no need to go through the 2 steps initPortsipSDK()above registerPortsip().

If you want to re-register from the beginning, you must initialize the SDK again as in section II .

⇒ When login is successful: event onRegisterSuccess()occurs.

⇒ Conversely, when it fails, the event onRegisterFailure()occurs.

IV. Log out of extension

V. Making an outgoing call

To make a call:

When the call recipient accepts the call:

event onInviteAnswered()occurs

When the call recipient rejects the call/the call is not answered/or for some reason the call is unsuccessful:

event onInviteFailure()occurs

Actively end the call:

VI. Receive call (incoming call)

Portsip Mobile Push needs to be applied so that the application can receive calls in inactive cases:

  • User not on application screen

  • Lock screen

  • Kill app

6.1. Set up mobile push

To use mobile push, you need to declare your iOS application to the portsip system through the following steps:

  • Generate certificate for VoIP Push and APN Push for iOS app

  • Create 1 Apple Certificate fileand Apple Private key file (no password)(2 files .pem)

  • Send these 2 files to eTelecom to create more Mobile Push

See details at: https://www.portsip.com/ios-mobile-push-portsip-pbx sections 4,5 and 9

6.2. Reality

When there is a call to the extension:

Event onInviteIncoming()occurs.

To receive calls : need to use Portsip Mobile Push, iOS services like CallKit, ForceBackground, PushKit.

  • Contact eTelecom to create more Mobile Push

  • Enable these features on XCode:

Reference about CallKit: https://developer.apple.com/documentation/callkit(opens new window)

Declare the following global variables:

  • voipRegistry: PKPushRegistry! = PKPushRegistry(queue: DispatchQueue.main). Used to declare receiving notifications from Portsip Mobile Push.

  • _VoIPPushToken: String = "". Token used to receive VoIP notifications.

  • _APNsPushToken: String = "". Token used to receive general notifications.

  • _cxProvider: CXProvider!. Used to display incoming call popup

  • _cxCallController: CXCallController = CXCallController(). Used to manipulate CallKit calls such as hanging up, answering, ...

The class AppDelegateimplements the following interfaces: UIApplicationDelegate, PKPushRegistryDelegate,CXProviderDelegate

class AppDelegateimports the following services: PushKit, UserNotifications,CallKit

There must be at least 2 functions application()in the file.AppDelegate.swift

  • 1 default application function. Here, enable CallKit (to be able to receive calls, make and receive calls in background mode), PushNotification (to use Portsip Mobile Push), ForceBackground (to let the app run in background mode)

  • 1 application function used to get device token used for receiving notifications

There must be at least 2 functions pushRegistry()in the file.AppDelegate.swift

  • 1 pushRegistry function used to get token used for receiving VoIP notifications

  • 1 pushRegistry function is used to receive VoIP notifications from Portsip Mobile Push. When a call comes in, portsip will send a notification to the user's device.

Declare Header with _VoIPPushToken and _APNsPushToken before calling API Registeror RefreshRegistrationportsipSDK (section II step 1).

Using CallKit to announce incoming calls, it can be implemented as follows:

Some actions that users can perform when receiving a call from CallKit: Accept (pick up the phone), Reject, Hang up (after accepting), ...

When the call ends, to turn off the CallKit calling screen :

When the user turns off the app, turns off the phone screen or kills the app, it is necessary to keep portsipSDK awake, so that the app is always ready to receive incoming calls.

VII. Video call

First, we create a swift file (for example: VideoCallViewController.swift) that inherits UIViewController. This file will be linked to the one ViewControllercreated through the steps 2 và 3.

Open file Main.storyboardasInterface Builder

Create a ViewController (eg: VideoCallViewController). Click the "+" sign on the top-right corner of the xCode screen ⇒ search for "View Controller" ⇒ Double Click or Enter.

⇒ We will have a ViewController like this:

On this screen, on the Custom Classright side, we find and select the VideoCallViewController class created in step 1.

Then, in the section Identity, we Storyboard IDcan optionally set an ID for this ViewController, and check the checkbox Use Storyboard IDbelow.

⇒ Try Open file Main.storyboardas Source Code, we will see the following code:

In this ViewController, we build the necessary components (1 area to contain RemoteVideo - video from the customer, 1 area to contain LocalVideo - your own video, 1 button to End Call, buttons such as Turn On/Off Speakerphone, switch front and rear Camera, ...)

  • Create 2 connection outlets, used to attach videos to 2 areas RemoteVideo and LocalVideo. How to attach will be presented in the next step.

  • In the demo code below, there is only 1 area to contain RemoteVideo, 1 area to contain LocalVideo, 1 button to End Call.

In the file VideoCallViewController.swift(created in step 1), declare the following variables:

In file AppDelegate.swift:

  • Declare more variables var videoCallView: VideoCallViewController!.

  • When the extension login is successful, an event onRegisterSuccess()occurs, in this event, initialize the values ​​for VideoCallView:

Make a video call, call the function call()with parameter videoCall= true

⇒ When the called person picks up the phone: the event onInviteAnswered()occurs.

In file VideoCallViewController.swift:

  • Declare 2 more variables

  • When the view is initialized for the first time, we must call the initVideoRender() function for remoteVideo and localVideo.

  • Once the view is displayed, assign the videos to localVideo and remoteVideo.

  • When the End Call button is clicked:

  • When the view is closed, remove the current video from localVideo and remoteVideo.

When a call comes in, the event onInviteIncoming()occurs

⇒ When you pick up the phone:

Last updated