iOS SDK V2 - Reference
The Plivo iOS SDK allows you to create applications capable of making and receiving calls in your iOS app. This document gives an overview of different classes and methods available in Plivo iOS SDK v2.
iOS 14 Compatibility Notice: Plivo iOS SDK 2.1.17+ is fully compatible with iOS 14.
For more information, check here
Initialization of Application
Registering an endpoint
With options
The following code demonstrates registering an endpoint using a Plivo SIP URI & password with options.
Without options
The following code demonstrates registering an endpoint using a Plivo SIP URI & password without options.
Access to Microphone
We have to provide Microphone access before making an outbound call or receiving an incoming call using AVFoundation
Examples for basic call actions
Making an outbound call
The following code demonstrates making an outbound call from the SDK.
Receiving a call
The following code demonstrates receiving an incoming call in the SDK.
Note: For more information on implementing incoming call in your iOS application, see the push notification section.
Classes and Methods
Class: PlivoEndpoint (PlivoEndpoint.h)
PlivoEndpoint (PlivoEndpoint.h) class allows you to register a Plivo SIP Endpoint. Once an endpoint is registered, you can make or receive calls using the endpoint. The following are the methods available in the PlivoEndpoint class.
Method 1: Registering an Endpoint
You can register an endpoint using:
- Username, Password, Device Token and Certificate ID
- Username, Password, and Device Token.
- Username, Password, and Timeout.
- Username and Password.
Registering an Endpoint- Using Username, Password, Device Token, and Certificate ID
Following are the parameters to be passed:
- username: Username of the endpoint.
- password: Password of the endpoint.
- token: Device token for VOIP push notifications. Device token from APNS can be obtained by registering for Push Notifications.
- certificateId: certificate Id created in plivo console. Manage Push credentials
If the endpoint is successfully registered, a notification is sent to the registerSuccess delegate. In case of a failure, a notification is sent to the registerFailure delegate.
Note: This is the recommended Login method to enable Incoming calls using Push Notifications.
USAGE
Registering an Endpoint- Using Username, Password and Device Token
Following are the parameters to be passed:
- username(username of the endpoint).
- password(password of the endpoint).
- token(device token for VOIP push notifications), Device token from APNS can be obtained by registering for Push Notifications.
If the endpoint is successfully registered a notification would be sent to the delegate registerSuccess. In case of a failure, a notification is sent to the delegate registerFailure.
Usage
Registering an Endpoint- Using Username, Password, and Timeout
Following are the parameters to be passed:
- username(username of the endpoint).
- password(password of the endpoint).
- regTimeout(Expiration time for registration in seconds).
If the endpoint is successfully registered a notification would be sent to the delegate registerSuccess. In case of a failure, a notification is sent to the delegate registerFailure.
Usage
Registering an Endpoint- Using Username and Password
Following are the parameters to be passed:
- username(username of the endpoint).
- password(password of the endpoint).
If the endpoint is successfully registered, a notification will be sent to the registerSuccess delegate. In case of a failure, a notification is sent to the registerFailure delegate.
Usage
Method 2: Unregister an Endpoint
This method is used to unregister an endpoint.
Method 3: Create Object for initiating Outbound calls
Calling this method returns a PlivoOutgoing object, linked to the registered endpoint. Calling this method on an unregistered PlivoEndpoint object returns an empty object.
Method 4: Submit call quality feedback
Following are the parameters to be passed:
- callUUID - Mandatory string parameter used to identify the call the feedback belongs to. You can get the callUUID for last call using getLastCallUUID()
- starRating - Mandatory integer parameter with a value from 1 to 5. For a score from 1 to 4, the issues parameter is mandatory and optional for a score of 5.
- issues - IssueList is an Array and must have at least one of the following reasons listed below for starRating value from 1 to 4 - ‘AUDIO_LAG’, ‘BROKEN_AUDIO’, ‘CALL_DROPPPED’, ‘CALLERID_ISSUES’, ‘DIGITS_NOT_CAPTURED’, ‘ECHO’, ‘HIGH_CONNECT_TIME’, ‘LOW_AUDIO_LEVEL’, ‘ONE_WAY_AUDIO’, ‘ROBOTIC_AUDIO’, ‘OTHERS’
- comments - Optional string attribute for users remarks, with a max length of 280 characters
- sendConsoleLog - Boolean optional parameter with default value false. Set this to true to enable Plivo’s team to collect and analyze iOS SDK’s logs for a better understanding of the issue.
If the feedback is successfully submitted, a notification would be sent to the delegate “onFeedbackSuccess”. In case of any input validation error, a notification would be sent to the delegate “onFeedbackValidationError”. If the feedback submission fails, the “onFeedbackFailure” delegate is notified.
Usage
Method 5: Get call UUID
Returns a string call UUID if a call is active, else returns null.
Usage
Method 6: Get last call UUID
Returns the call UUID of the latest answered call. Useful in the case if you want to send feedback for the last call.
Usage
Class: PlivoOutgoing (PlivoOutgoing.h)
PlivoOutgoing class contains methods to make and control an outbound call.
Method 1: Initiate Outbound calls
Calling this method on the PlivoOutgoing object with the SIP URI would initiate an outbound call.
Method 2: Initiate Outbound calls with custom SIP headers
Calling this method on the PlivoOutgoing object with the SIP URI would initiate an outbound call with custom SIP headers.
Usage
Method 3: Mute a call
Calling this method on the PlivoOutgoing object mutes the call.
Usage
Method 4: Unmute a call
Calling this method on the PlivoOutgoing object unmutes the call.
Usage
Method 5: Send Digits
Calling this method on the PlivoOutgoing object with the digits sends DTMF on that call. DTMF input only supports 0-9 , *, and #.
Usage
Method 6: Hangup a call
Calling this method on the PlivoOutgoing object would hang up the call.
Usage
Method 7: Hold a call
Calling this method on the PlivoOutgoing object disconnects the audio devices during an audio interruption.
Usage
Method 8: Unhold a call
Calling this method on the PlivoOutgoing object reconnects the audio devices after an audio interruption.
Description
Usage
Class: PlivoIncoming(PlivoIncoming.h)
PlivoIncoming class contains methods to handle the incoming call. An object of this class will be received on the following delegate.
Method 1: Answer an Incoming call
Calling this method on the PlivoIncoming object answers the call.
Usage
Method 2: Reject an Incoming call
Calling this method on the PlivoIncoming object rejects the call.
Usage
Configuration Parameters
The following are the configuration parameters:
Attribute | Description | Allowed Values | Default Value |
---|---|---|---|
debug | Enable log messages | true/false | false |
enableTracking | Set to true if you want to get mediaMetrics events and enable call quality tracking. | true/false | true |
maxAverageBitrate | This param may be used to control your application’s bandwidth consumption for calls. A higher maxAverageBitrate value may result in more bandwidth consumption, but also better audio quality. Lowering the maxAverageBitrate impacts call quality as the audio is compressed to a greater extent to reduce bandwidth consumption. This param only applies to calls using Opus codec. Check out RFC-7587 section 7.1 for more info. | 8000 - 48000 | 48000 |
PlivoEndpoint Delegates
Delegate 1: On Login
Delegate
Description When registration to an endpoint is successful.
Parameters Error details
Return Value None
Delegate 2: Handling Login Failure
Delegate
Description This delegate gets called when registration to an endpoint fails.
Parameters None
Return Value None
Delegate 3: Handling Login Failure with Errors
Delegate
Description This delegate gets called when registration to an endpoint fails.
Parameters Error details
Return Value None
Delegate 4: On Incoming Call
Delegate
Description This delegate gets called when there is an incoming call to a registered endpoint
Parameters Incoming object
Return Value None
Delegate 5: On Incoming Call Rejected
Delegate
Description On an incoming call, if the call is disconnected by the caller, this delegate would be triggered with the PlivoIncoming object.
Parameters Incoming object
Return Value None
Delegate 6: On Incoming Call Hangup
Delegate
Description On an incoming call, if the call is disconnected by the caller after being answered, this delegate would be triggered with the PlivoIncoming object.
Parameters Incoming object
Return Value None
Delegate 7: On Incoming Digit
Delegate
Description On an active endpoint, this delegate would be called with the digit received on the call.
Parameters String for DTMF digit
Return Value None
Delegate 8: On Incoming Call Answered
Delegate
Description This delegate gets called when the incoming call is answered and audio is ready to flow.
Parameters Incoming object
Return Value None
Delegate 9: On Incoming Call Invalid
Delegate
Description For an incoming call, this delegate gets called when the callee does not accept or reject the call in 40 seconds or SDK is not able to establish a connection with Plivo.
Parameters Incoming object
Return Value None
Delegate 10: On Calling
Delegate
Description When an outgoing call is initiated, this delegate would be called with the PlivoOutgoing object.
Parameters Outgoing object
Return Value None
Delegate 11: On Outgoing Call Ringing
Delegate
Description When an outgoing call is ringing, this delegate would be called with the PlivoOutgoing object.
Parameters Outgoing object
Return Value None
Delegate 12: On Outgoing Call Answer
Delegate
Description When an outgoing call is answered, this delegate would be called with the PlivoOutgoing object.
Parameters Outgoing object
Return Value None
Delegate 13: On Outgoing Call Rejected
Delegate
Description When an outgoing call is rejected by the called number, this delegate would be called with the PlivoOutgoing object.
Parameters Outgoing object
Return Value None
Delegate 14: On Outgoing Call Hangup
Delegate
Description When an outgoing call is disconnected by the called number after the call has been answered.
Parameters Outgoing object
Return Value None
Delegate 15: On Outgoing Call Invalid
Delegate
Description When an outgoing call is made to an invalid number, this delegate would be called with the PlivoOutgoing object.
Parameters Outgoing object
Return Value None
Delegate 16: MEDIA METRICS
Description For an ongoing call, if any of the below events are triggered, the mediaMetrics delegate will be called with respective values of the event in the mediaMetrics object.
Parameters mediaMetrics object
Return Value None
Events | Description | Example | ||
---|---|---|---|---|
high_jitter | when the jitter is higher than 30 ms for 2 out of the last 3 samples. This event will be generated individually for the local stream and remote stream. | { group: ‘network’, level: ‘warning’, type: ‘high_jitter’, active: true/false, // false when the value goes to normal level (last 2 out of 3 samples have jitter less than 30 ms) value: ‘<average jitter value>’, desc: ‘high jitter detected due to network congestion, can result in audio quality problems’, stream: ‘local || remote’ } | ||
high_rtt | When the RTT is higher than 400 ms for 2 out of the last 3 samples | { group: ‘network’, level: ‘warning’, type: ‘high_rtt’, active: true/false, // false when value goes to normal level (last 2 out of 3 samples have RTT less than 400 ms) value: ‘<average rtt value>’, desc: ‘high latency detected, can result in delay in audio’, stream: ‘None’ } | ||
high_packetloss | When the packet loss is > 10% for OPUS and loss > 2% PCMU. This event will be generated individually for the local stream and remote stream. | { group: ‘network’, level: ‘warning’, type: ‘high_packetloss’, active: true/false, // false when value goes to normal level value: ‘<average packet loss value>’, desc: ‘high packet loss is detected on media stream, can result in choppy audio or dropped call’, stream: ‘local || remote’ } | ||
low_mos | When sampled mos is < 3.5 for 2 out of the last 3 samples. | { group: ‘network’, level: ‘warning’, type: ‘low_mos’, active: true/false, // false when value goes to normal level. value: ‘<current_mos_value>’, desc: ‘low Mean Opinion Score (MOS)’, stream: ‘None’ } | ||
no_audio_received | When remote or local audio is silent This event will be generated individually for the local stream and remote stream. | { group: ‘audio’, level: ‘warning’, type: ‘no_audio_received’, active: true/false, // false when value goes to normal level value: ‘<current_value_in_dB>’, desc: ‘no audio packets received’ stream: ‘local | remote’ } |
Receiving Incoming SIP Headers
You can receive custom SIP headers on an incoming call as a part of the PlivoIncoming object on the ‘onIncomingCall’ delegate. For example:
Resetting your Endpoint
If you choose to manually reset your endpoints and disable their WebSocket transport, you can use the resetEndpoint method as shown below:
Please ensure that you initialize the endpoint after reset, as shown above, otherwise, WebSocket transport will not be re-initialized and your application will not be able to communicate with Plivo servers.
Methods supporting Pushkit and Callkit in PlivoEndpoint
APIs for pushkit Integration
Method 1: Register Token
This method is used to register the device token for VOIP push notifications.
Method 2: Relay Push Notification
pushInfo is the NSDictionary object forwarded by the apple push notification.
Usage
APIs for Callkit Integration
The following are the three APIs that are required for Apple Callkit integration.
Method 1: Configure Audio Session
This method is used to Configure audio session before the call.
Method 2: Start Audio Device
Depending on the call status (Hold or Active) you’ll want to start or stop processing the call’s audio. Use this method to signal the SDK to start audio I/O units when receiving the audio activation callback from CallKit.
Method 3: Stop Audio Device
Depending on the call status(Hold or Active) you’ll want to start, or stop processing the call’s audio, use this method to signal the SDK to stop audio I/O units when receiving deactivation or reset callbacks from CallKit
Usage
To Configure Audio
Start the Audio service to handle audio interruptions use AVAudioSessionInterruptionTypeBegan and AVAudioSessionInterruptionTypeEnded.
To turn on the speakers
To turn off the speakers