Skip to content

nixonsam/plivo-ios-quickstart-app

 
 

Repository files navigation

Plivo Voice Quickstart for iOS

plivo-ios-quickstart-app

The Plivo iOS SDK v2 allows you to make outgoing and receive incoming calls in your iOS application.

Supports Pushkit and Callkit. Eliminates the need for persistent connections to recieve incoming calls.

Compatible with iOS version 8 and above.

Plivo iOS SDK now supports IPv6 networks. Users can make and receive calls when their device is connected to a network that uses IPv4, IPv6, or both versions of the protocol.

To get started with the quickstart application follow these steps. Steps 1-3 will enable the application to make a call. The remaining steps 4-5 will enable the application to receive incoming calls in the form of push notifications using Apple’s VoIP Service.

  1. Install the PlivoVoiceKit framework using Cocoapods

  2. Create Endpoints

  3. Register and Unregister Endpoint

  4. Run the app

  5. Plivo iOS SDK V2 with Push Kit integration

  6. Making an outgoing call

  7. Receive an incoming call

1. Install the PlivoVoiceKit framework using Cocoapods

It's easy to install the Voice framework if you manage your dependencies using Cocoapods. Simply add the following to your Podfile:

pod 'PlivoVoiceKit'

SDK Reference - More documentation related to the Voice iOS SDK

2. Create Endpoints

Signup and create endpoints with Plivo using below link

Plivo Dashboard

3. Register and Unregister Endpoints

Implement SIP register to Plivo Communication Server

To register with Plivo's SIP and Media server , use a valid sip uri account from plivo web console

var endpoint: PlivoEndpoint = PlivoEndpoint(["debug": true])

// To register with SIP Server
func login( withUserName userName: String, andPassword password: String) {
    endpoint.login(userName, andPassword: password)
}

// To register with SIP Server using device token for getting Push Notifications
func login(withUserName userName: String, andPassword password: String, deviceToken token: Data) {
    endpoint.login(userName, andPassword: password, deviceToken: token)
}

//To unregister with SIP Server
func logout() {
    endpoint.logout()
}

If the registration to an endpoint fails the following delegate gets called

(void)onLoginFailedWithError:(NSError *)error;

4. Run the app

Open SwiftVoiceCallingApp.xcworkspace.

Build and run the app.

Enter sip endpoint username and password.

After successful login make VoiceCalls.

5. Plivo iOS SDK V2 with Push Kit integration

To enable Pushkit Integration in the SDK the login with deviceToken and relayVoipPushNotification are implemented

//Register pushkit token using the login method as mentioned above
func login(withUserName userName: String, andPassword password: String, deviceToken token: Data) {
    endpoint.login(userName, andPassword: password, deviceToken: token)
}

//receive and pass on (information or a message)
func relayVoipPushNotification(_ pushdata: [AnyHashable: Any]) {
    endpoint.relayVoipPushNotification(pushdata)
}

please refer to below link on Generating VoIP Certificate.

Generating VoIP Certificate

6. Making an outgoing call

Create PlivoOutgoingCall object , then make a call with destination and headers

func call(withDest dest: String, andHeaders headers: [AnyHashable: Any], error: inout NSError?) -> PlivoOutgoing {
    /* construct SIP URI , where kENDPOINTURL is a contant contaning domain name details*/
    let sipUri: String = "sip:\(dest)\(kENDPOINTURL)"
    /* create PlivoOutgoing object */
    outCall = (endpoint.createOutgoingCall())!
    /* do the call */
    outCall?.call(sipUri, headers: headers, error: &error)
    return outCall!
}

//To Configure Audio
func configureAudioSession() {
    endpoint.configureAudioDevice()
}

configureAudioSession - use this callkit method to set up the AVAudioSession with desired configuration.

Make an outbound call

Calling this method on the PlivoOutgoing object with the SIP URI would initiate an outbound call.

(void)call:(NSString *)sipURI error:(NSError **)error;

Make an outbound call with custom SIP headers

Calling this method on the PlivoOutgoing object with the SIP URI would initiate an outbound call with custom SIP headers.

(void)call:(NSString *)sipURI headers:(NSDictionary *)headers error:(NSError **)error;

7. Receive an incoming call

// MARK: PKPushRegistryDelegate
func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, forType type: PKPushType) {
    if credentials.token.count == 0 {
    print("VOIP token NULL")
    return
    }

    // This method is used to register the device token for VOIP push notifications.
    Phone.sharedInstance.login(withUserName: userName, andPassword: password, deviceToken: credentials.token)
}

//When the push arrives below delegate method will be called. 
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
    if (type == PKPushType.voIP) {
    Phone.sharedInstance.relayVoipPushNotification(payload.dictionaryPayload)
    }
}

PushInfo is the NSDictionary object forwarded by the apple push notification. This will enable the application to receive incoming calls even the app is not in foreground.

You are now ready to receive incoming calls.

plivo-ios-quickstart-app

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 75.4%
  • Objective-C 23.8%
  • Ruby 0.8%