Notes
New changes for the iOS SDK
- To use the new SDK, developers must add Plivo’s custom-built WebRTC framework, which also supports bitcode and is available on SPM, Carthage, and CocoaPods.
- The SDK is backward compatible. Note: In Objective-C applications login-related methods will report an error regarding method signature placeholder. Previously methods were exposed for Obj-C as login(_ username: String, AndPassword password: String) and for Swift as login(_ username: String, andPassword password: String). Now in both Swift and Obj-C we use the same login(_ username: String, andPassword password: String).
Terminology
- username: username of an endpoint
- password: password of an endpoint
- token: device token for VoIP push notifications. You can obtain a device token from APNS by registering for push notifications.
- certificateId: certificate ID created in the Plivo console under Voice > Push Credentials — see push credentials documentation
Register an endpoint
With options
This code demonstrates registering an endpoint using a Plivo SIP URI and password with options.Without options
This code demonstrates registering an endpoint using a Plivo SIP URI and password without options.Access the microphone
We have to provide microphone access before making an outbound or receiving an incoming call using the AVFoundation multimedia framework.Examples for basic call actions
Here are a couple of basic code examples for making and receiving a call.Make a call
This code makes an outbound call to an endpoint using the SDK.Receive a call
This code receives an incoming call using the SDK.Note: For more information on implementing incoming calls in your iOS application, see our documentation on Setting Up Push credentials.
Classes and methods
Class: PlivoEndpoint (PlivoEndpoint.h)
The PlivoEndpoint (PlivoEndpoint.h) class lets you register a Plivo SIP endpoint, after which you can make and receive calls using it. Methods available in the PlivoEndpoint class let you register and unregister an endpoint, create an object for outbound calls, submit call quality feedback, and get a call UUID.Method 1: Register an endpoint
With UserName and Password
You can register an endpoint using:- Username, password, device token, and certificate ID
- Username, password, and device token
- Username and password
Registering an endpoint using username, password, device token, and certificate ID
Note: This is the recommended login method to enable incoming calls using push notifications
USAGE
Registering an endpoint using username, password, and device token
USAGE
Registering an endpoint using username, password, and timeout
Note: This is the recommended login method to enable incoming calls using push notifications
USAGE
Registering an endpoint using username and password
USAGE
Method 2: Unregister an endpoint
This method unregisters an endpoint. (void)logout;Method 3: Create an 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. (PlivoOutgoing*)createOutgoingCall;Method 4: Submit call quality feedback
You can pass these parameters.- callUUID — Mandatory string parameter used to identify the call the feedback belongs to. You can get the callUUID for the 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; for a score of 5 it’s optional. - issues — IssueList is an array and must have at least one of these reasons for &
starRating&
values 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; maximum length 280 characters
- sendConsoleLog — Optional boolean parameter with default value &
false&
. Set to &true&
to enable Plivo’s team to collect and analyze the iOS SDK’s logs for a better understanding of the issue.
usage
Method 5: Get a 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 if you want to send feedback for the last call.usage
Method 7: Set Register Timeout
Set the registration timeout in seconds. Useful if you want the registratino to be valid for upto certain timeusage
Class: PlivoOutgoing (PlivoOutgoing.h)
The PlivoOutgoing class contains methods to make and control outbound calls.Method 1: Initiate outbound calls
Calling this method on the PlivoOutgoing object with the SIP URI initiates an outbound call.Method 2: Initiate outbound calls with custom SIP headers
Calling this method on the PlivoOutgoing object with the SIP URI initiates 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 digits sends DTMF (0-9 , *, and #) on the call. (void)sendDigits:(NSString*)digits;usage
Method 6: Hang up a call
Calling this method on the PlivoOutgoing object disconnects the call.usage
Method 7: Hold a call
Calling this method on the PlivoOutgoing object disconnects the audio devices.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)
The PlivoIncoming class contains methods to handle an incoming call. A reference of this class is received in the parameter of this delegate. You can use this class reference to answer and reject the call. (void)incomingCall:(PlivoIncoming*) incoming;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
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 digits sends DTMF (0-9 , *, and #) on the call.usage
Method 6: Hang up a call
Calling this method on the PlivoOutgoing object disconnects the call.usage
Method 7: Hold a call
Calling this method on the PlivoOutgoing object disconnects the audio devices.usage
Method 8: Unhold a call
Calling this method on the PlivoOutgoing object reconnects the audio devices after an audio interruption.Description:
usage
Configuration parameters
These 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 | Controls your application’s bandwidth consumption for calls. A high maxAverageBitrate value yields better audio quality but may result in more bandwidth consumption. Lowering maxAverageBitrate impacts call quality as the audio is compressed to reduce bandwidth consumption. This parameter applies only to calls using the Opus codec. Check out RFC-7587 section 7.1 for more info. | 8000 – 48000 | 48000 |
enableQualityTracking | This parameter can be used to enable/disable below two functionalities: mediaMetrics events: enables the Client device to display local call issues like broken audio, etc. to the user. Call quality tracking: enables Plivo to capture and display call quality data in Call Insights. When set to ‘all’ Both mediaMetrics events & call quality tracking will be enabled. When set to ‘remoteonly’ only call quality tracking will be enabled. When set to ‘localonly’ only mediaMetrics events will be enabled. When set to ‘none’ Both mediaMetrics events & call quality tracking will be disabled. | CallAndMediaMetrics.ALL CallAndMediaMetrics.NONE CallAndMediaMetrics.REMOTE_ONLY CallAndMediaMetrics.LOCAL_ONLY | CallAndMediaMetrics.ALL |
PlivoEndpoint delegates
Delegate 1: On login
Delegate 2: Handling login failure
Delegate 3: Handling login failure with errors
INVALID_ACCESS_TOKEN
INVALID_ACCESS_TOKEN_HEADER
INVALID_ACCESS_TOKEN_ISSUER
INVALID_ACCESS_TOKEN_SUBJECT
ACCESS_TOKEN_NOT_VALID_YET
ACCESS_TOKEN_EXPIRED
INVALID_ACCESS_TOKEN_SIGNATURE
INVALID_ACCESS_TOKEN_GRANTS
EXPIRATION_EXCEEDS_MAX_ALLOWED_TIME
MAX_ALLOWED_LOGIN_REACHED
Delegate 4: On incoming call
Delegate 5: On incoming call rejected
Delegate 6: On incoming call hangup
Delegate 7: On incoming digit
Delegate 8: On incoming call answered
Delegate 9: On incoming call invalid
Delegate 10: On calling
Delegate 11: On outgoing call ringing
Delegate 12: On outgoing call answer
Delegate 13: On outgoing call rejected
Delegate 14: On outgoing call hangup
Delegate 15: On outgoing call invalid
Delegate 16: On logout
Delegate 17: MediaMetrics
Description: This delegate is called if any of the below events are triggered on an ongoing call. Parameters: MediaMetrics object Return Value: NoneEvents | Description | Example |
---|---|---|
high_jitter | When jitter is higher than 30 milliseconds for two out of the last three samples. This event is 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 round-trip time (RTT) is higher than 400 milliseconds for two out of the last three 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 packet loss is > 10%. This event is 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 mean opinion score (MOS) is < 3.5 for two out of the last three 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 is 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 an endpoint
To manually reset endpoints and disable their WebSocket transport, use the resetEndpoint method. [PlivoEndpoint resetEndpoint]; self.endpoint = [[PlivoEndpoint alloc] init]; Be sure to initialize the endpoint after reset, as shown above, or WebSocket transport will not be reinitialized 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
Use this method to register the device token for VoIP push notifications.Method 2: Relay VoIP push notification
pushInfo
is the NSDictionary object forwarded by the Apple push notification.
USAGE
APIs for CallKit integration
These three APIs are required for Apple CallKit integration.Method 1: Configure audio session
This method configures an audio session before a call.Method 2: Start audio device
Depending on the call status (Hold or Active) you can start or stop processing the call’s audio. Use this method to signal the SDK to start audio I/O units when you receive an audio activation callback from CallKit.Method 3: Stop audio device
Depending on the call status (Hold) you can start or stop processing the call’s audio. Use this method to signal the SDK to stop audio I/O units when you receive deactivation or reset callbacks from CallKit.USAGE
To configure audio
To turn on speakers
To turn off speakers
setAVAudioSessionPortOverride:none