iOS SDK

The Plivo iOS SDK allows you to create applications capable of making and receiving calls in your iOS app.

Download the SDK (v0.4)

Examples using the SDK


Basic Calling Examples

Register an endpoint

NSString *username = @"Tatooine";
NSString *password = @"Jabba";
PlivoEndpoint *endpoint = [[PlivoEndpoint alloc] init];
[endpoint login:username AndPassword:password];

Make an outbound call

NSString *username = @"Tatooine";
NSString *password = @"Jabba";
PlivoEndpoint *endpoint = [[PlivoEndpoint alloc] init];
[endpoint login:username AndPassword:password];

NSString *toURI = @"sip:Coruscant@phone.plivo.com";

PlivoOutgoing *outgoing = [endpoint createOutgoingCall];
[outgoing call:toURI];

Receive a call

NSString *username = @"Tatooine";
NSString *password = @"Jabba";
PlivoEndpoint *endpoint = [[PlivoEndpoint alloc] init];
[endpoint login:username AndPassword:password];

endpoint.delegate = self;

- (void)onIncomingCall:(PlivoIncoming*)incoming
{
    // Answer the call
    [incoming answer];
}

PlivoEndpoint.h

PlivoEndpoint class allows you to register a Plivo SIP Endpoint. Once an endpoint is registered, calls can be made or received using the same.

- (void)login:(NSString*) username AndPassword:(NSString*) password;

This method is used to register an endpoint. 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.

  • @param username The username of the endpoint created on Plivo
  • @param password The password of the endpoint created on Plivo
  • @returns None
- (void)logout;

This method is used to unregister an endpoint.

  • @param None
  • @returns None
- (PlivoOutgoing*)createOutgoingCall;

Calling this method would return an PlivoOutgoing object, linked to the registered endpoint. Calling this method on an unregistered PlivoEndpoint object would return an empty object.

  • @param None
  • @returns PlivoOutgoing object which can be used to make outbound calls

PlivoOutgoing.h

PlivoOutgoing class contains methods to make and control an outbound call.

- (void)call:(NSString*) sipURI;

This method would make an outbound call to the sipURI.

  • @param sipURI The sipURI to make a call to.
  • @returns None
- (void)mute;

Calling this method on the PlivoOutgoing object would mute the call.

  • @param None
  • @returns None
- (void)unmute;

Calling this method on the PlivoOutgoing object would unmute the call.

  • @param None
  • @returns None
- (void)sendDigits:(NSString*)digits;

Calling this method on the PlivoOutgoing object with the digits would send DTMF on that call.

  • @param digits A string of digits which needs to be sent
  • @returns None
- (void)hangup;

Calling this method on the PlivoOutgoing object would hangup the call.

  • @param None
  • @returns None

PlivoIncoming.h

PlivoIncoming class contains methods to handle incoming call. An object of this class will be received on the - (void)incomingCall:(PlivoIncoming*) incoming; delegate.

- (void)answer;

This method is used to answer an incoming call.

  • @param None
  • @returns None
- (void)mute;

This method is used to mute the call.

  • @param None
  • @returns None
- (void)unmute;

This method is used to unmute the call. Calling this method on an already unmuted call won’t have any effect.

  • @param None
  • @returns None
- (void)sendDigits:(NSString*) digits;

Calling this method on the PlivoIncoming object with the digits would send DTMF on that call.

  • @param digits The digits to be sent as a NSString
  • @returns None
- (void)disconnect;

Calling this method on the PlivoIncoming object would disconnect the call.

  • @param None
  • @returns None
- (void)reject;

Calling this method would reject the incoming call.

  • @param None
  • @returns None

PlivoEndpoint.h delegates

- (void)onLogin;

This delegate gets called when registration to an endpoint is successful.

- (void)onLoginFailure;

This delegate gets called when registration to an endpoint fails.

- (void)onIncomingCall:(PlivoIncoming*)incoming;

On an incoming call to a registered endpoint, this delegate receives a PlivoIncoming object.

- (void)onIncomingCallRejected:(PlivoIncoming*)incoming;

On an incoming call, if the call is disconnected by the caller, this delegate would be triggered with the PlivoIncoming object.

- (void)onIncomingCallHangup:(PlivoIncoming*)incoming;

On an incoming call, if the call is disconnected by the caller after being answered, this delegate would be triggered with the PlivoIncoming object.

- (void)onIncomingDigit:(NSString*)digit;

On an active endpoint, this delegate would be called with the digit received on the call.

- (void)onOutgoingCallAnswered:(PlivoOutgoing*)call;

When an outgoing call is answered, this delegate would be called with the PlivoOutgoing object.

- (void)onOutgoingCallRinging:(PlivoOutgoing*)call;

When an outgoing call is ringing, this delegate would be called with the PlivoOutgoing object.

- (void)onOutgoingCallRejected:(PlivoOutgoing*)call;

When an outgoing call is rejected by the called number, this delegate would be called with the PlivoOutgoing object.

- (void)onOutgoingCallHangup:(PlivoOutgoing*)call;

When an outgoing call is disconnected by the called number after the call has been answered.

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.

Example

- (void)onIncomingCall:(PlivoIncoming*)incoming
{
    if ([incoming.extraHeaders count] > 0) {
        NSLog(@"-- Incoming call extra headers --");
        for (NSString *key in incoming.extraHeaders) {
            NSString *value = [incoming.extraHeaders objectForKey:key];
            NSLog(@"%@ => %@", key, value);
        }
    }
    // Answer the call here.
}

Resetting your Endpoint

You must manually reset your endpoint object and create a new object in the case, where;

  1. Your application goes in and out of network connectivity
  2. Your application became active after coming up from the background
  3. Your application is about to be terminated

Example

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [self.endpoint resetEndpoint];
    self.endpoint = [[PlivoEndpoint alloc] init];
}

Changelog

v0.4 - 2015-02-16

  • Hard reset of endpoints
  • Improved support for PlivoEndpoint delegates
  • Fixed crash on calling login() multiple times
  • Disabled default debug logging
  • Bug fix: onLogout delegate not being called when the endpoint logs out

v0.3 - 2013-10-26

  • Get SIP Call ID
  • Bug fix : hangup invalid call causing app to crash
  • Improvement : Build SIP URI if user only supply digit as call destination
  • Bug fix : onOutgoingCallInvalid delegate causing app to crash
  • Bug fix : delegate/notification creating new call object. We should use existing call object

v0.2 - 2013-10-09

  • Receive incoming custom SIP headers