iOS SDK

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

Download the SDK

Examples using the SDK

Basic Calling Stuff

Register an endpoint


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

Make an outbound call


  NSString *toURI = @"sip:Coruscant@phone.plivo.com";
  PlivoOutgoing *outgoing = [endpoint createOutgoingCall];
  [outgoing call:toURI];

Receive a call


  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 a 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.

Backgrounding

The iOS SDK enables your app to work in the background. Which means you will be able to receive calls even when the app in minimized.

Add ‘Required Background Modes’ key in the Info plist of your application. The values are : ‘App plays audio’ and ‘App provides Voice over IP services’

Add setKeepAliveTimeoutHandler to re-login in your applicationDidEnterBackground. As described here

Example

[self.endpoint keepAlive];
    [[UIApplication sharedApplication] setKeepAliveTimeout:600 handler:^{
        [self.endpoint keepAlive];
    }];

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.
}